zoukankan      html  css  js  c++  java
  • JavaScript 很长很长的JS

    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);
    

      

  • 相关阅读:
    redis性能优化——生产中实际遇到的问题排查总结
    Redis优化经验
    Python 发送 email 的两种方式
    封装简单的equery
    Mobiscroll的介绍【一款兼容PC和移动设备的滑动插件】
    css3毛玻璃模糊效果
    环形进度条的实现方法总结和动态时钟绘制(CSS3、SVG、Canvas)
    CSS实现圆角,三角,五角星,五边形,爱心,12角星,8角星,圆,椭圆,圆圈,八卦
    盘点8种CSS实现垂直居中水平居中的绝对定位居中技术
    CSS 去掉inline-block间隙的几种方法
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/8893975.html
Copyright © 2011-2022 走看看