title: how to stop recursion and/or restart the current function with updated variables
body: <p>I've got two arrays which are updating themselves and each other based on criteria (it is way longer to describe than I suspect the solution is). </p>
  
  <p>What I end up with is a function which calls itself within a while loop. As you can imagine, this causes a ridiculous amount of recursion. </p>
  
  <p>Here's an example (keeping it short)</p>
  
  <pre>
  var buildArray=firstFunction(new Array(), existingArray)
  
  function firstFunction(thisArray, existingArray){
       for(test1=0; test1&lt;existingArray.length; test1++){
           if(existingArray[test1][3]=='2'){
             secondFunction(thisArray, existingArray, test1);
          }
       }
  
  function secondFunction(thisArray, existingArray, t1){
         for(test2=0; test2&lt;thisArray.length; test2++){
            if(thisArray[test1]&lt;=existingArray[test2][1] || thisArray[test1]&gt;existingArray[test2[0]){
              // do a bunch of stuff to existingArray, now that existingArray has changed, the whole process needs to start again FROM THE BEGINNING!!!
       return firstFunction(new Array(), existingArray);
  
                // check that the value isn't already in the 'thisArray'
     var check= new Array(existingArray[test1]);
    else if (jQuery.inArray(check, thisArray==-1){
           // value isn't in the new array, so add it
          thisArray.push(check);
         // thisArray has changed. need to restart the the second function
         secondFunction(thisArray,existingArray);
       }
  
     }
   }
  
  }
  }
  </pre>
  
  <p>I was hoping that </p>
  
  <pre>return secondFunction(thisArray, existingArray);
  </pre>
  
  <p>would reset and restart the function, but apparently that isn't happening. </p>
  
  <p>Is there a way to stop the current function and loops and restart with the updated variables? </p>