Diff Two Arrays 001

Tell us what’s happening:
This is kind of a dumb question, but I am trying to understand the === -1 part of the filter callback function. Can anyone explain this to me so I can better understand how the code is working? Thank u!

Your code so far


function diffArray(arr1, arr2) {
  var newArr = [];
 
 let filter1 = arr1.filter((value) => {
   return arr2.indexOf(value) === - 1;
 });
 let filter2 = arr2.filter((value) => {
   return arr1.indexOf(value) === - 1;
 })
  return filter1.concat(filter2);
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36.

Link to the challenge:

The method indexOf returns -1 if the item is not in the array.

1 Like