Hi!
I have a code, but it was not working, then I decided to turn it into an arrow function, and then it worked, but I don’t know why! I mean, the code is EXACTLY the same, but it works with arrow function and not the other way. I have already checked the typo MANY times, and there is none. But there should be something I am missing out.
This is the non-working code:
function destroyer(arr) {
var newArr = [];
newArr = arguments[0];
for (var i = 1; i < arguments.length; i++){
newArr = newArr.filter(function(x){return x != arguments[i];})
}
return newArr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
This is the working code:
function destroyer(arr) {
var newArr = [];
newArr = arguments[0];
for (var i = 1; i < arguments.length; i++){
newArr = newArr.filter(x => x != arguments[i])
}
return newArr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);