Seek and Destroy?

function destroyer(arr) {
  // Remove all the values
  var destroyed = [];
  for (var i = 1; i < arguments.length; i++) {
    destroyed = arguments[0].filter(function(item) {
      return (item !== arguments[i]);
    });
  }
  return destroyed;
}

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

I don’t really get what’s going on even after running through the debugger. Could anyone please tell me what’s wrong with this code?

Hi
Two things stand out.

  • You are reassigning to destroyed from arguments[0] once each iteration of your for…loop.
  • arguments is a keyword that means ‘all arguments of this function’ so inside your filter function it is not the arguments you think it is.

Thanks!! I knew I did something wrong using arguments and your answer helped a lot!