I found a lot of posts that solve this problem:
Assuming we have:
array1 = ['A', 'B', 'C', 'D', 'E']; array2 = ['C', 'E'];
Is there a proven and quick solution for comparing two arrays with each other, returning one array without the values ββdisplayed in both arrays (here and here C and E). Desired solution:
array3 = ['A', 'B', 'D']
But what if you have:
array1 = ['A', 'B', 'C', 'D', 'D', 'E']; array2 = ['D', 'E'];
and you are looking for a solution:
array3 = ['A', 'B', 'C', 'D'] // don't wipe out both D's
Here is the context:
You are trying to teach students how sentences work. You give them an encrypted sentence:
ate - cat - mouse - the -
They begin to type the answer: Cat
You want the prompt to appear:
ate - mouse -
Currently my code is returning both.
Here is what I tried:
(zsentence is a copy of xsentence that will be processed by the code below, join () ed and placed on the screen)
for (i=0; i < answer_split.length; i++) { for (j=0; j < xsentence.length; j++) { (function(){ if (answer_split[i] == xsentence[j]) { zsentence.splice(j,1); return; } })(); } }