您好我需要篩選具有相同地址的企業(陣列)和創建這樣一個數組:濾波器陣列/反應
[{address:uniqueaddress1,organization:[company1,company2]},
{address:uniqueaddress2,organization:[company3,company4]
.....]
我使用下面的代碼:
var organizations = [];
var dataPoints = [];
for (var i = 0; i < companies.length; i++) {
for (var j = 0; j < companies.length; j++) {
if (i === j) continue;
if (companies[j].address === companies[i].address) {
organizations.push(companies[j]);
companies[j].added = true; //To mark it is added
}
dataPoints.push({address:companies[j].address, organizations: companies[j]});
}
}
原始數組:
0:Object
added:true
address:"sample address 1"
id:258
latitude:90.90227
longitude:12.538208
name:"Company name 1"
postalCode:"90450"
什麼是原來的陣列? – Ted
@Ted編輯問題 – user8125765
等一下!這不是針對超級的CodeFights機器人嗎?哈哈 – Ted