Tell us what’s happening:
I was able to eliminate the first instance of the arguments, however i can’t eliminate multiple instances. I think I might have to count the number of instances each arg shows up in the array but I’m not sure how to do this optimally.
Your code so far
function destroyer(arr) {
// Remove all the values
for(let i = 1; i < arguments.length;i++){
if(arr.includes(arguments[i])){
const index = arr.indexOf(arguments[i]);
if (index > -1) {
arr.splice(index, 1);
}
}
}
console.log(arr);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.
Challenge: Seek and Destroy
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy