• js排序--一道js数据结构题


    给一个数组:

    [{ GroupMark: "", GroupName: "hao", SendTime: '123', SendContent: "1ha" },
    { GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "2ha" },
    { GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "3ha" },
    { GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "4ha" },
    { GroupMark: "3", GroupName: "hao", SendTime: '123', SendContent: "6ha" },
    { GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "5ha" }]

    目标

    [{"GroupMark":"","GroupName":"hao","SendTime":"123","SendContent":["1ha"]},
    {"GroupMark":"1","GroupName":"hao","SendTime":"123","SendContent":["2ha","3ha"]},
    {"GroupMark":"22","GroupName":"hao","SendTime":"123","SendContent":["4ha","5ha"]},
    {"GroupMark":"3","GroupName":"hao","SendTime":"123","SendContent":["6ha"]}]

    //参照数组去重的
    var
    arr =[{ GroupMark: "", GroupName: "hao", SendTime: '123', SendContent: "1ha" }, { GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "2ha" }, { GroupMark: "1", GroupName: "hao", SendTime: '123', SendContent: "3ha" }, { GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "4ha" }, { GroupMark: "3", GroupName: "hao", SendTime: '123', SendContent: "6ha" }, { GroupMark: "22", GroupName: "hao", SendTime: '123', SendContent: "5ha" }] var tempObj ={} var resArr = [] for(let [index,item] of arr.entries() ){ let {GroupMark,GroupName,SendContent} = item let keyStr = GroupMark+'&'+GroupName if(tempObj[keyStr]){ let tempSendContent= tempObj[keyStr].SendContent tempObj[keyStr].SendContent=[...tempSendContent,SendContent] }else{ tempObj[keyStr]={ ...item, SendContent:[SendContent] } } } for (let item in tempObj) { resArr.push(tempObj[item]) } console.log(resArr)

  • 相关阅读:
    Android JNI和NDK学习(04)--NDK调试方法(转)
    Android JNI和NDK学习(03)--动态方式实现JNI(转)
    Android JNI和NDK学习(02)--静态方式实现JNI(转)
    Android JNI和NDK学习(01)--搭建NDK开发环境(转)
    C++语言基础(7)-inline内联函数
    C++语言基础(6)-const 关键字
    C++语言基础(5)-this和static关键字
    红黑树:个人理解与Python实现
    最小堆实现优先队列:Python实现
    二叉查找树:Python实现
  • 原文地址:https://www.cnblogs.com/forest-king/p/10444051.html
Copyright © 2020-2023  润新知