I have the following piece of code:
function destroyer(arr) {
for(var i=1; i<arguments.length; i++){
var kill = arguments[i];
arr = arr.filter(function(x){return x != kill;});
}
return arr;
}
console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));
It removes the elements from an array which equal the optional arguments. This code gives [1,1] as I expect.
But if I change the 4th line to
arr = arr.filter(function(x){return x != arguments[i];});
I get [1,2,3,1,2,3] instead, when I expect [1,1]. Why is that the case?
argumentsobject of the inner function and not the outer one.arr = arr.filter(x => x != arguments[i]);