第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

js 循環(huán)**數(shù)據(jù)結(jié)構(gòu)處理**問題, 遇到瓶頸,求方案(考慮性能)

js 循環(huán)**數(shù)據(jù)結(jié)構(gòu)處理**問題, 遇到瓶頸,求方案(考慮性能)

數(shù)據(jù)結(jié)構(gòu)描述var users = [     {id: 1, username: '123', authPlayerIds: [1001, 1002, 1003]},     {id: 2, username: 'qwe', authPlayerIds: [1003, 1004, 1005]},     {id: 3, username: 'fdf', authPlayerIds: [1002, 1007, 1088]},     {id: 4, username: 'dsa', authPlayerIds: [1001, 1022, 1033]},     ...    // 注意: 數(shù)據(jù)在`20000`以上]需求描述計(jì)算authPlayerIds字段中的每一項(xiàng)(id)所出現(xiàn)的次數(shù)以及包含它的用戶(user)性能優(yōu)先(首選)處理結(jié)束后的數(shù)據(jù)結(jié)構(gòu)var authPlayers = {     '1001': [         {id: 1, username: '123'},         {id: 4, username: 'dsa'}     ],    '1002': [         {id: 1, username: '123'},         {id: 3, username: 'fdf'},         {id: 4, username: 'dsa'},     ],    '1003': [         {id: 1, username: '123'},         {id: 2, username: 'qwe'},     ] }語言及工具描述JavaScriptNode.jsLodashunderscoreasyncbluebird一切你想用的工具都可以在線急等...是時(shí)候表演真正的技術(shù)了
查看完整描述

2 回答

?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊

var authPlayers = {};

        for(var i=0;i<users.length;i++){

            var use = users[i];

            var useIds = users[i].authPlayerIds;

            delete use.authPlayerIds;

            for(var j=0;j<useIds.length;j++){

                if( authPlayers[useIds[j]] == undefined ){

                    authPlayers[useIds[j]]=[];

                    authPlayers[useIds[j]].push(use);

                }else{

                    authPlayers[useIds[j]].push(use);

                }

                //console.log( authPlayers[useIds[j]]  )

            }

        }


查看完整回答
反對 回復(fù) 2018-10-29
?
大話西游666

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊

var users = [

    {id: 1, username: '123', authPlayerIds: [1001, 1002, 1003]},

    {id: 2, username: 'qwe', authPlayerIds: [1003, 1004, 1005]},

    {id: 3, username: 'fdf', authPlayerIds: [1002, 1007, 1088]},

    {id: 4, username: 'dsa', authPlayerIds: [1001, 1022, 1033]},

]

var ret = {}

users.forEach(function(e){

    var ap = e.authPlayerIds

    ap.forEach(function(p){

        var t = {}

        if (ret[p]) {

            t.id = e.id || null

            t.username = e.username || null

        } else {

            ret[p] = []

            t.id = e.id || null

            t.username = e.username || null

        }

        ret[p].push(t)

    })

})


查看完整回答
反對 回復(fù) 2018-10-29
  • 2 回答
  • 0 關(guān)注
  • 997 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號