Hi, i’m doing the ‘Seek and Destroy’ JavaScript Challenge:
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
and here is my code.
function destroyer(arr) {
var newArr = ;
for (var i=0;i<arguments[0].length;i++){
if (arguments[0][i] == arguments[1] || arguments[0][i] == arguments[2]){arguments[0].splice(i,1); } else { newArr.push(arguments[0][i]); }
}
return newArr;
}
The problem that I ran into is that it doesn’t work for string type input such as:
destroyer([“tree”, “hamburger”, 53], “tree”, 53) should return [“hamburger”].
Can anyone help me to solve the problem? Also, the challenge suggests to use ‘array.filter()’.
Thx