Tell us what’s happening:
I got stuck in this problem so I peeked at the solution and almost wrote the same approach as the first solution, however for some reason it only works when I call the function twice while switching the parameters location in the function call. I would love if someone can explain to me why is this not working.
It only works when I call the function twice in a row for somereason, would love some explanation to why it did not work
Describe your issue in detail here.
**Your code so far**
function diffArray(arr1, arr2) {
const newArr = [];
function newTry(first, second){
for (let i=0; i < first.length; i++ ){
if(second.indexOf(first[i]) === -1){
newArr.push(first[i])
console.log(newArr)
}
}
}
newTry(arr1, arr2)
newTry(arr2, arr1)
return newArr;
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Challenge: Diff Two Arrays
Link to the challenge: