Can someone help me understand what is going on with my code? I can’t get it to pass all the tests… Not sure what is going on though, because the ones it is failing have multiple of the same element that need to be destroyed; it seems like the 2nd element remains. Yet in other examples from the testing, it removes all of them. I’m confused and any help/explanation would be appreciated!
function destroyer(arr) {
let i = 0,
x = 0;
while (i < arguments.length){
for(x in arr) {
if(arr[x] == arguments[i]) {
arr.splice(x,1)
}
}
i++;
}
console.log(arr);
return arr;
}
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3);
It only fails these tests:
destroyer([3, 5, 1, 2, 2], 2, 3, 5)
should return [1]
.
destroyer([2, 3, 2, 3], 2, 3)
should return []
.
The rest pass.