Seek and Destroy the cats?


I’m really confused, really. I forgot all my other coding sessions and now came to solve this huuuuuuuuuge algorithm with my tiny brain and guess what I failed exactly as you’d expect…

So I went to my friend google and he pointed me to this answer from github.

function destroyer(arr) {
  var args =;
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1; // HERE!

The place where Im not understanding is at the line 5. It’s really confusing there. I am not undrstanding that part.
From what I have understood, that line usually checks through the given array’s elements and checks if their index is… huh? that’s where I go wrong, the indexOf(elem) function and why it’s equating to a negative number…

indexof returns an index if it finds the element, if it doesn’t then it returns -1. After that it compares it with -1, so if index is -1 then -1 === -1 is true and returns that, true; In other words, it returns true if that element doesn’t exist in the array and false if it does.

In the current version of JavaScript, there’s a more appropriate way of checking if an element is present in an array: includes()

does it work with objects?

includes() only works on arrays and strings. For checking if an object has a particular key there is hasOwnProperty(). There’s no built-in method for checking if a specific value is present in any of object’s properties.

Sorry about that, my question was not very specific xD
I meant the element you pass as a parameter, it checks the value or if it’s the same object?

Strictly speaking, you pass arguments to a function, not parameters. When a function is invoked, the values passed to the function (arguments) are assigned to function parameters, which practically are just local variables.

includes() compares objects using strict equality (===).

Thanks for helping guys

1 Like