Seek and Destroy - arguments doesnt work

Seek and Destroy - arguments doesnt work
0

#1

I think I made a decent code concerning the Seek and Destroy challenge. One part I do not understand.
When I change arguments[i] in the if statement to 1,2 or 3 here,or any other integer,which presents the “destroyer number”, the code seems to work. But my arguments[i] wont work. When I set it arguments[1] or arguments[2] or something like that,it also doesnt work. What seems to be the problem?

function destroyer(arr) {
  var filtered = arguments[0].filter(function(val) {
    for (var i = 1; i < arguments.length; i++) {
      if (val !== arguments[i]) {return true;}
      return false;
    }  
  });
  return filtered;
}

#2

The arguments inside the callback function are not the same arguments for the destroyer function.

I added some console.log statements to your code, so you can run and see how the two arguments are different.

function destroyer(arr) {
  console.log('destroyer function arguments below');
  console.log(arguments);
  console.log(''); // blank line
  var filtered = arguments[0].filter(function(val) {
    console.log('the anonymous callback function arguments are below');
    console.log(arguments);
    for (var i = 1; i < arguments.length; i++) {
      console.log('val = ' + val + ' AND arguments[' + i + '] = ' + arguments[i]);
      if (val !== arguments[i]) {return true;}
      return false;
    }
    console.log(''); // blank line
  });
  return filtered;
}

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

Running the above results in:

destroyer function arguments below
{ 0: [ 1, 2, 3, 1, 2, 3 ], 1: 2, 2: 3 }

the anonymous callback function arguments are below
{ 0: 1, 1: 0, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 1 AND arguments[1] = 0
the anonymous callback function arguments are below
{ 0: 2, 1: 1, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 2 AND arguments[1] = 1
the anonymous callback function arguments are below
{ 0: 3, 1: 2, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 3 AND arguments[1] = 2
the anonymous callback function arguments are below
{ 0: 1, 1: 3, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 1 AND arguments[1] = 3
the anonymous callback function arguments are below
{ 0: 2, 1: 4, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 2 AND arguments[1] = 4
the anonymous callback function arguments are below
{ 0: 3, 1: 5, 2: [ 1, 2, 3, 1, 2, 3 ] }
val = 3 AND arguments[1] = 5

Remember that the filter callback function has access two three arguments (1st is the current element, 2nd is the current element’s index, and the 3rd is the original array the filter was called on). That is why you are see properties 0, 1, 2 in callback function arguments.