i've got 2 arrays updating , each other based on criteria (it way longer describe suspect solution is).
what end function calls within while loop. can imagine, causes ridiculous amount of recursion.
here's example (keeping short)
var buildarray=firstfunction(new array(), existingarray) function firstfunction(thisarray, existingarray){ for(test1=0; test1<existingarray.length; test1++){ if(existingarray[test1][3]=='2'){ secondfunction(thisarray, existingarray, test1); } } function secondfunction(thisarray, existingarray, t1){ for(test2=0; test2<thisarray.length; test2++){ if(thisarray[test1]<=existingarray[test2][1] || thisarray[test1]>existingarray[test2[0]){ // bunch of stuff existingarray, existingarray has changed, whole process needs start again beginning!!! return firstfunction(new array(), existingarray); // check value isn't in 'thisarray' var check= new array(existingarray[test1]); else if (jquery.inarray(check, thisarray==-1){ // value isn't in new array, add thisarray.push(check); // thisarray has changed. need restart the second function secondfunction(thisarray,existingarray); } } } } }
i hoping
return secondfunction(thisarray, existingarray);
would reset , restart function, apparently isn't happening.
is there way stop current function , loops , restart updated variables?
i not trying yo do, based on fact return stop execution in secondfunction, , thisarray never changed, can add loop firstfunction:
function firstfunction(thisarray, existingarray){ var restart = true; while(restart) { restart = false; for(test1=0; !restart && test1<existingarray.length; test1++){ if(existingarray[test1][3]=='2'){ if(secondfunction(thisarray, existingarray, test1)) { restart = true; } } } }
and in secondfunction instead of returning array return true:
if(thisarray[test1]<=existingarray[test2][1] || thisarray[test1]>existingarray[test2[0]){ // bunch of stuff existingarray, existingarray has changed, whole process needs start again beginning!!! return true;
Comments
Post a Comment