Seek and destroy javascript

Tell us what’s happening:
this is my code for intermediate algorithm scripting challenge: seek and destroy in java script algorithms and data structure.

I’ve worked out my code manually but i cannot seem to understand why some of the tests are not working on my code.

would appreciate if anyone could point out my mistake.

Your code so far


function destroyer(arr) {
var args = arr.slice.call(arguments).length;
var array = arguments[0].slice(0);
for(var i = 1; i < args; i++){
  for(var j = 0; j < arguments[0].length; j++){
    if(array[j] == arguments[i]){
      arguments[0].splice(j,1);
  

    }
  }
}

return arr;
}

destroyer([2, 3, 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/84.0.4147.89 Safari/537.36.

Challenge: Seek and Destroy

Link to the challenge:

you are mutating the array on which you are iterating, causing unexpected effects

don’t mutate the array on which you are iterating over

1 Like