Tell us what’s happening:
Please i’m very confused on why the code below is giving a different result, ive been trying to crack through the logic on why it is not giving the desired result yet i can’t figure it out. Guess my head is currently blocked lol! Please can someone tell me what wrong with this code, why its outputting [1,2] instead of [1]. thanks
Your code so far
function destroyer(arr) {
for(let i = 1; i < arguments.length; i++){
for(let j = 0; j < arr.length; j++){
if(arguments[i] === arr[j]){
var seekIndex = j;
arr.splice(seekIndex,1);
}
}
}
return arr;
}
console.log(destroyer([3, 5, 1, 2, 2], 2, 3, 5));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Seek and Destroy
Link to the challenge: