title: Javascript -- Compare two arrays, return differences, BUT
body: <p>I've found a lot of posts that solve this problem:</p>
  
  <p>Assuming we have:</p>
  
  <pre><code>array1 = ['A', 'B', 'C', 'D', 'E']; array2 = ['C', 'E'];
  </code></pre>
  
  <p>Is there a proven and fast solution to compare two arrays against each other, returning one array without the values appearing in both arrays (C and E here). Desired solution:</p>
  
  <pre><code>array3 = ['A', 'B', 'D']
  </code></pre>
  
  <p>But what if you have:</p>
  
  <pre><code>array1 = ['A', 'B', 'C', 'D', 'D', 'E']; array2 = ['D', 'E'];
  </code></pre>
  
  <p>and you're looking for the solution to be:</p>
  
  <pre><code>array3 = ['A', 'B', 'C', 'D'] // don't wipe out both D's
  </code></pre>
  
  <p>Here is some context:</p>
  
  <p>You are trying to teach students about how sentences work. You give them a scrambled sentence:</p>
  
  <p>ate -- cat -- mouse -- the -- the</p>
  
  <p>They start typing an answer: The cat</p>
  
  <p>You would like the prompt to now read:</p>
  
  <p>ate -- mouse - the </p>
  
  <p>At present, my code takes out both the's.</p>
  
  <p>Here is what I've tried:<br>
  (zsentence is a copy of xsentence that will get manipulated by the code below, join()ed and put to screen)</p>
  
  <pre><code>for (i=0; i &lt; answer_split.length; i++) {
  for (j=0; j &lt; xsentence.length; j++) {
          (function(){
              if (answer_split[i] == xsentence[j]) { zsentence.splice(j,1); return; }
          })();
      }
  }
  </code></pre>