博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript 很长很长的JS
阅读量:6226 次
发布时间:2019-06-21

本文共 2402 字,大约阅读时间需要 8 分钟。

var BaiduUsers = [], WechatUsers = [];var User = function(id, name, phone, gender, age, salary) {this.id = id;this.name = name;this.phone = phone;this.gender = gender;this.age = age;this.salary = salary;};User.create = function(id, name, phone, gender, age, salary) {    return new User(id, name, phone, gender, age, salary);};BaiduUsers.push(User.create(1, 'tommy', '1111','male', 18, 10000));BaiduUsers.push(User.create(2, 'jerry', '2222','male', 28, 10000));BaiduUsers.push(User.create(3, 'raobin','3333','female', 14, 1200));BaiduUsers.push(User.create(4, 'binbin','4444','male', 23, 9800));BaiduUsers.push(User.create(5, 'arthur','5555','female', 22, 10000));WechatUsers.push(User.create(1, 'tommy', '1111','male', 20, 40000));WechatUsers.push(User.create(2, 'allen', '6666','male', 34, 15800));WechatUsers.push(User.create(3, 'raobin','3333','female',16, 2300));WechatUsers.push(User.create(4, 'harvey','7777','male',30, 29800));WechatUsers.push(User.create(5, 'yuyu',  '8888','female',27, 7000));var newusers = [];var len1=WechatUsers.length;var len =WechatUsers.length+1;newusers =myFunction(newusers);function myFunction(user){for  (var i = 0; i < BaiduUsers.length; i++) {for (var y = 0; y< WechatUsers.length; y++) {if (BaiduUsers[i].phone==WechatUsers[y].phone){newusers.push(User.create(WechatUsers[y].id,WechatUsers[y].name,WechatUsers[y].phone,WechatUsers[y].gender,WechatUsers[y].age,WechatUsers[y].salary+BaiduUsers[i].salary)); } else {newusers.push(User.create(len++,BaiduUsers[i].name,BaiduUsers[i].phone,BaiduUsers[i].gender,BaiduUsers[i].age,BaiduUsers[i].salary*1.2)); }} }return user}var hash = {};newusers = newusers.reduce(function(item, next) {    hash[next.phone] ? '' : hash[next.phone] = true && item.push(next);    return item}, [])console.log(newusers);var newusers2= [];newusers2 =myFunction(newusers2);function myFunction(user){for  (var i = 0; i < WechatUsers.length; i++) {for (var y = 0; y< newusers.length; y++) {if (newusers[i].phone!=WechatUsers[y].phone){newusers2.push(User.create(WechatUsers[i].id,WechatUsers[i].name,WechatUsers[i].phone,WechatUsers[i].gender,WechatUsers[i].age,WechatUsers[i].salary)); } } }return user}var hash = {};newusers2 = newusers2.reduce(function(item, next) {    hash[next.phone] ? '' : hash[next.phone] = true && item.push(next);    return item}, [])console.log(newusers2);

  

转载于:https://www.cnblogs.com/qianjinyan/p/8893975.html

你可能感兴趣的文章
作业:实现简单的shell sed替换功能和修改haproxy配置文件
查看>>
Altium 拼板方法以及 注意的 地方
查看>>
PMP考试的过与只是
查看>>
java 监控 收集资料3(收集中)
查看>>
Apache Pulsar中的地域复制,第1篇:概念和功能
查看>>
getRealPath()和getContextPath()的区别
查看>>
python pip install 出现 OSError: [Errno 1] Operation not permitted
查看>>
oracle12C 重做日志
查看>>
awk-sed
查看>>
zookeeper与kafka安装部署及java环境搭建(发布订阅模式)
查看>>
手写Json转换
查看>>
编码规约
查看>>
LeetCode OJ:Min Stack(最小栈问题)
查看>>
JS判断数组方法大全
查看>>
Tftod 的服务器使用下载文件
查看>>
从源码分析scrollTo、scrollBy、Scroller方法的区别和作用
查看>>
数字电路建模 - jchdl
查看>>
( 转)UVM验证方法学之一验证平台
查看>>
编写每天定时切割Nginx日志的脚本
查看>>
我们一起来聊聊并发吧,one。
查看>>