Hi any and all, I’m seeking assistance with the “Seek and Destroy” algorithm scripting challenge.
function destroyer(arr) {
const arg = arguments[0];
for (let i = 1; i < arguments.length; i++) {
for (let j = 0; j < arg.length; j++) {
if (arguments[0][j] === arguments[i]) {
arguments[0].splice(arguments[0].indexOf(arguments[i]), 1);
console.log(arguments[0]);
}
}
}
return arguments[0];
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
All tests but two are passing:
destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1]
destroyer([2, 3, 2, 3], 2, 3) should return [].
It seems like all but the last value is being returned. For the first one I’m getting [1,2]
and for the second I’m getting [3]
.