title: Efficient way to compare two arrays
body: <p>I am using two arrays to accomplish a task of checking if values in array1 exist in array2. If so remove the content in array1 and keep checking till array1 is empty. If they dont exist just return from the function. I am using Javascript</p>
  
  <p>I implemented it using classic two for loops which gives a run time of o(n*2). I would like to know if there is any other efficient way to perform this operation using any other data structure that javascript supports. Below is my current implementation</p>
  
  <pre><code>for(var j = 0; j &lt; tempArray.length; j++){
       for(var k = 0; k &lt; this.probsSolved.length; k++){
           if(tempArray[j] == this.probsSolved[k]){
               tempArray.splice(j,1);            
               if(tempArray.length &lt;= 0){
                   this.updateAchievements(achID);
                   this.storage.set(achKey,1);
                   return;
               }         
       }
  }
  </code></pre>
  
  <p>The thing is I have to call the function under which this operation is performed every 5 seconds and this for me looks highly inefficient.</p>
  
  <p>Could someone suggest a better algorithm or a data structure that performs better than the one above that I can use and how would I use if so.</p>