Hi Hugh, not quite sure what the (==-1) in this line does…
James Sison
11

So, filter iterates over an array, in this case number by number. We want filter the numbers contained in arr , so we compare them against the numbers in args using indexOf. indexOf will return -1 if the value being tested (from the array) doesn’t appear in args.

var arr = [1, 2, 3]
console.log(arr.indexOf(1))
// logs "0" because 1 is at index 0.
console.log(arr.indexOf(4))
// logs "-1" because 4 does not appear in the array

Any number that returns -1 won’t be filtered as it is being returned by filter method to the arr. Any value which fails this test will be removed.

return arr.filter(function (value){
return args.indexOf(value) === -1;
});

I hope that helps.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.