Tell us what’s happening:
Describe your issue in detail here.
I’m having an issue understanding how this solution works exactly…
if(b.indexOf(a[i])=== -1)
This aspect of the solution is confusing me, it seems -1 identifies the desired element but I don’t get why.
**Your code so far**
function diffArray(arr1, arr2) {
const newArr = [];
function abSwapper (a, b) {
for(let i = 0; i < a.length; i++) {
if(b.indexOf(a[i])=== -1) {
newArr.push(a[i])
}
}
}
abSwapper(arr1, arr2);
abSwapper(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/96.0.4664.55 Safari/537.36
Challenge: Diff Two Arrays
Link to the challenge: