Hello All. So I’m having problems with the challenge called seek and destroy, more importantly the indexOf method in JavaScript.
I’ve seen the answer for the challenge but I would like some help explaining a line or two
The Answer:
function destroyer(arr) { var args = Array.prototype.slice.call(arguments); args.splice(0, 1); return arr.filter(function(element) { return args.indexOf(element) === -1; }); }
The part that I’m having trouble understanding is creating a filter function and specifically
how the indexOf method works.
if someone could please explain in detail what it means in the line where it says:
return args.indexOf(elemnet) === -1;
To my understanding, what the line above is saying is, alright take the arguments list, and return only the arguments in this list that conform to the other two elements of the array in the initial function. However, I’m confused as to how it uses all of the arguments provided by the user at the beginning of the function, and how the -1 exists, especially when there is more than one instance of a single number in the array you’re trying to filter. All help is appreciated.