1.

Solve : increasing efficiency of for loops?

Answer»

Code: [Select] for (i=0; i<amo; i++){
//------Fleets on a location------//
if (num[i].parentNode.parentNode.parentNode.parentNode.className=="layout listing btnlisting sorttable") {
if (num[i].parentNode==num[i].parentNode.parentNode.childNodes[1]) {
split1=num[i].INNERHTML.split(" ",1)
for (j=0; j<ftags.length; j++) {
if (split1==ftags[j]) {
colorname(fcolor, '3', num[i].parentNode.parentNode);
var fnum=+num[i].parentNode.parentNode.childNodes[3].childNodes[0].innerHTML.replace(/\D/g,'')
if (num[i].parentNode.parentNode.childNodes[2].innerHTML=='') {ffleet=ffleet+fnum}
else {iffleet=iffleet+fnum}
}
}
for (j=0; j<etags.length; j++) {
if (split1==etags[j]) {colorname(ecolor, '3', num[i].parentNode.parentNode);
var fnum=+num[i].parentNode.parentNode.childNodes[3].childNodes[0].innerHTML.replace(/\D/g,'')
if (num[i].parentNode.parentNode.childNodes[2].innerHTML=='') {efleet=efleet+fnum}
else {iefleet=iefleet+fnum}
}
}
}
}
}

is there anyway of increasing the efficiency of this script?

at the moment it checks to see if a players guild tag is in one of two arrays. but i know the WAY that it is doing it is very inefficient because its  for loop within a for loop. if there is a match it goes to another function to change specific DIV tags colour depending on which guild the player is in.

so can anyone help with making it more efficient


the first for loop can go THREW about 1000 entry's (table ROWS)
for each entry it checks to see if the guild tag (split1) is within one of the two arrays, if its in the first it does one thing and if the tag is in the other array it does another thing



Discussion

No Comment Found