Seek and Destroy need help with my logic

Tell us what’s happening:

Can somebody help how to solve this task. I went over it several times and I cannot find my logical mistake. A hint would be great. Thanks :slight_smile:

Your code so far

function destroyer(arr) {
  // Remove all the values
  var result = arr.filter(newArr);
  
  function newArr(val) {
  for (var i = 1; i < arguments.length; i++) {
    for (var j = 0; j < arr.length; j++) {
        if(arguments[i] !== arr[j]) {
          return val;
        }
      }
    }
  }
    
  
  return result;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/seek-and-destroy

Look at what’s inside arguments:

function destroyer(arr) {
  console.log(arguments)
  // Remove all the values
  var result = arr.filter(newArr);
  
  function newArr(val) {
    console.log(arguments)
    for (var i = 1; i < arguments.length; i++) {
      for (var j = 0; j < arr.length; j++) {
        if(arguments[i] !== arr[j]) {
          return val;
        }
      }
    }
  }
    
  
  return result;
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));

Arguments are what’s passed into the function. You’re working with two functions. Each function has its own arguments object.

The following is mine, there are simmilar way of thinking but different way of code

function destroyer(arr){
    //convert arguments into array
    
    var args = Array.from(arguments);
    
    //comparing the indexes of array and arguments
    //and delete if it's equal
    for(var i in arr){
        for(var j in args){
            if(arr[i] === args[j]){
                delete arr[i];
            }
        }
    }
    // the expected result of arr would contain some null values 
    //therefore, we need to filter() those null 
    return arr.filter(arr => Boolean(arr));
}

thanks for your reminding :slight_smile: