Seek and Destroy Intermediate Algorithm Scripting Challenge

Hi any and all, I’m seeking assistance with the “Seek and Destroy” algorithm scripting challenge.

function destroyer(arr) {
const arg = arguments[0];
    for (let i = 1; i < arguments.length; i++) {
      for (let j = 0; j < arg.length; j++) {
        if (arguments[0][j] === arguments[i]) {
          arguments[0].splice(arguments[0].indexOf(arguments[i]), 1);
          console.log(arguments[0]);
        }
      }
    }
    return arguments[0];
  }
  destroyer([1, 2, 3, 1, 2, 3], 2, 3);

All tests but two are passing:

destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1]

destroyer([2, 3, 2, 3], 2, 3) should return [].

It seems like all but the last value is being returned. For the first one I’m getting [1,2] and for the second I’m getting [3].

Try filter()
MDN reference here

make a new array of all the numbers, loop them through filter and that should do it.

This helped, thanks a bunch! This was my solution:


function destroyer(arr) {
  arr = Array.from(arguments);
  let firstArr = arr[0];
  let args = arr.slice(1);
  let res = firstArr.filter(function(e) {
       return this.indexOf(e) < 0;
    }, args
    );
  return res;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);