Problems with Seek and Destroy

Problems with Seek and Destroy


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 =; 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.


I’m not a javascript expert but my understanding is that this line will return true if the element exists in the array args and false otherwise.

breaking it down:
args.indexOf(element) - checks the array args for element and returns it’s index if it is found and -1 if it is not found.

=== -1 - this a logical comparison of the result from the indexOf call and the number -1. It will be true when the indexOf result is -1 (ie the element was not found in the array) and false otherwise.

Does this clarify the process?