Why my solution is not working?

I have sliced the additional arguments and stored them in the values variable then looped over it and checked if the arr includes any value of the values array in a condition and then entered the condition and splice the value from arr

it did not work and I consoled the values were 1 and 3 and there is no 1 in the additional arguments why this is happening I have tried the same way with includes array method

function destroyer(arr) {
let values = Array.from(arguments).slice(1);

for (let i = 0; i < values.length; i++) {
  if (arr.indexOf(values[i])) {
    console.log(arr.splice(i, 1))
return arr

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/99.0.4844.82 Safari/537.36

Challenge: Seek and Destroy

Link to the challenge:

Splice changes the contents of the array

You shouldn’t change the contents of the array as you iterate over it - it leads to confusing results.

I’d make a new array instead.

A post was split to a new topic: Having issues with equality operator challenge

Making a copy of the array and doing the same thing with the copy won’t fix what I’m talking about.

If you remove the third item in an array, where does the fourth, fifth, etc one go?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.