Seek and Destroy why my wrong?

Tell us what’s happening:
why my method is not correct?

Your code so far

function destroyer(arr) {
  // Remove all the values
  return arr.filter(function(x) {
      for (var j = 1; j < arguments.length; ++j) {
        if (arguments[j] == x)   return false;
      }
      return true;
  });
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/seek-and-destroy

That’s because you have a different sets of arguments inside the filter function:

function destroyer(arr) {
 console.log(arguments) // here arguments is an object

return arr.filter(function(x) {
  console.log(arguments) // here arguments is different, it refers to the filter function
}
}

You can use ES6 arrow function, since they don’t have their own
arguments.

or store the one you need into a variable and access it inside the filter function

function d(arr){
  var myArgs = arguments...

 arr.filter(function(x) {
  // you can access myArgs here
}
}

hope it make sense :slight_smile:

3 Likes

Oh… I got it,thank you very much.:grinning: