Tell us what’s happening:
Describe your issue in detail here.
A couple of things before I get to my question:
- I believe this is probably not how I need to go at this problem in the first place, and I suspect this may be a roundabout way of tackling it.
- the console.log on line 10 is there just so I can see the result.
Looking at the results of my code, I’m left with an array [1, 2]. How does the 2 not get weeded out in the second or fifth iterations of the first for loop? Shouldn’t arguments[0][i] (when i == 1 or 4) be 2? So when arguments[j] is 2, wouldn’t that allow the second part of the if statement to splice out the 2 from the original array? Not sure if this is making sense, but I just don’t understand why the 2 is still in play. Never mind why the second 1 was removed as there should never be an arguments[j] == 1. Let me know if this is too convoluted a question. I’m confusing myself with it.
Thanks in advance.
Additionally I have changed:
let j = 0
to:
let j = 1
with no change to the result.
**Your code so far**
function destroyer(arr) {
let argsLength = arguments.length;
for (let i = 0; i < arguments[0].length; i++){
for(let j = 0; j < argsLength; j++){
if(arguments[0][i] == arguments[j]){
arguments[0].splice(arguments[0][i]);
}
}
}
console.log(arguments[0])
return arguments[0];
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36
Challenge: Seek and Destroy
Link to the challenge: