Javascript 在这段代码中有没有办法避免三个嵌套循环?
我知道这个问题可能不属于这里,但如果有人愿意,我可以提供一些建议 我想知道是否有任何方法可以更有效地编写以下代码 一般概念:Javascript 在这段代码中有没有办法避免三个嵌套循环?,javascript,performance,loops,Javascript,Performance,Loops,我知道这个问题可能不属于这里,但如果有人愿意,我可以提供一些建议 我想知道是否有任何方法可以更有效地编写以下代码 一般概念: 浏览最多6个相邻测量列表 检查列表是否包含任何非法组合(arfcn和bsic的组合) 如果不合法,则添加到报警列表(如果此列表中不存在) 代码如下: var bcch_sacch = [70, 0, 0, 0, 0, 0] var combo = [[70, 30], [0, 0]] var alarm; var ncellcount = message.data.rep
var bcch_sacch = [70, 0, 0, 0, 0, 0]
var combo = [[70, 30], [0, 0]]
var alarm;
var ncellcount = message.data.reports.numberofneighbors;
//Loop through neighbors measurements (up to 6)
for(var j = 0; j < 6; j++) {
//If j is less than the amount of neighbors in the list (0-6)
if(j < ncellcount) {
//Combo: allowed combinations
for(var i = 0; i < combo.length; i++) {
//If allowed
if(combo[i][0] == bcch_sacch[j] &&
combo[i][1] == message.data.reports.neighboringCells[j].BSIC) {
}
else {
for(var d = 0; d < alarm.length; d++) {
//If the current arfcn(j) and bsic(j) is in the alarms list
if(alarm[d][0] == bcch_sacch[j] &&
alarm[d][1] == message.data.reports.neighboringCells[j].BSIC) {
}
else {
//Add the combo in the alarm list
alarm[alarm.length][0] = bcch_sacch[j];
alarm[alarm.length][1] = message.data.reports.neighboringCells[j].BSIC;
}
}
}
}
}
}
//Print out the alarms list in a table
for(var s = 0; s < alarm.length; s++) {
$('#alarms tr:last').after('<tr><td>'+alarm[s][0]+'</td><td>'+alarm[s][1]+'</td></tr>');
}
var bcch_sacch=[70,0,0,0,0]
变量组合=[[70,30],[0,0]]
无功报警;
var ncellcount=message.data.reports.numberOfNeights;
//循环通过相邻测量值(最多6个)
对于(var j=0;j<6;j++){
//如果j小于列表中的邻居数量(0-6)
如果(j
首先,使用Array.filter(用于查找非法组合)和Array.some(用于查找现有报警)可能会使代码更可读。首先,使用Array.filter(用于查找非法组合)和Array.some(用于查找现有报警)可能会使代码更可读。