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.