zoukankan      html  css  js  c++  java
  • 数组对象 级别 交集

    有以下数据:
     let a = new Set([
        {
            'categoryId': 1,
            'categoryIdLevelOne': 750611334,
            'categoryIdLevelThree': 750611336,
            'categoryIdLevelTwo': 750611335,
            'id': 2697,
            'level': 3,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 1
        },
        {
            'categoryId': 2,
            'categoryIdLevelOne': 750611472,
            'categoryIdLevelTwo': 750611473,
            'id': 2701,
            'level': 2,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 2
        },
        {
            'categoryId': 3,
            'categoryIdLevelOne': 750611487,
            'categoryIdLevelTwo': 750611488,
            'id': 2702,
            'level': 2,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 1
        }
    ])
    let b = new Set([
        {
            'categoryId': 2,
            'categoryIdLevelOne': 750611334,
            'categoryIdLevelThree': 750611336,
            'categoryIdLevelTwo': 750611335,
            'id': 2697,
            'level': 3,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 1
        },
        {
            'categoryId': 3,
            'categoryIdLevelOne': 750611472,
            'categoryIdLevelTwo': 750611473,
            'id': 2701,
            'level': 2,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 2
        },
        {
            'categoryId': 4,
            'categoryIdLevelOne': 750611487,
            'categoryIdLevelTwo': 750611488,
            'id': 2702,
            'level': 2,
            'shopId': 12430,
            'skipLayoutFlag': false,
            'status': 1
        }
    ])
    
    交集
    [...a].filter(x => [...b].some(y => y.categoryId === x.categoryId))
    
    //或者
    
    Array.from(a).filter(x => Array.from(b).some(y => y.categoryId === x.categoryId))
    
    差集
    
    [...a].filter(x => [...b].every(y => y.categoryId !== x.categoryId))
    
    去重
    
     this.selectTable = this.selectTable.reduce(function(item, next) {
            hash[next.id] ? "" : (hash[next.id] = true && item.push(next));
            return item;
          }, []);
  • 相关阅读:
    sql server支持gb18030里面的疑难中文字
    sql:把多列的数据转成行的一个字段
    CVS转SVN
    关于linux语言的设置
    [转]Windows server 2008网络负载均衡集群
    Get和Post、幂等、净荷
    EA经典教程
    Emeditor 斜线显示为人民币符号
    map和set(关于iterator失效的问题)
    scoket和浏览器的连接限制
  • 原文地址:https://www.cnblogs.com/nns4/p/11348148.html
Copyright © 2011-2022 走看看