Seek and Destroy filter function

Hello, I am new to this whole programming thing and struggling with algorithms right now.

I have come up with this solution, however I can’t seem to get the return part of my filter function right.

function destroyer(arr) {
// Remove all the values
//turn arguments into array, starting from the second (1) arg
var args = Array.prototype.slice.call(arguments,1);

 //filter function, return value that doesn't match the arguments
 function destroyThis(val){
   for (var i = 0; i < args.length; i ++){  
     //return args.indexOf(x) === -1;
     **return val != args[i];**
   }
 }
  
  //filter the working array
 arr = arr.filter(destroyThis);
 return arr;
}

Can anyone help me with the bold part? My current solution only check the last of the arguments.
Much appreciate. :slight_smile:

Oh, thank you so much. I wanted to try another option :grin:

I thought by writing “return val != args[i]” I was returning the val that is not args[i]. Silly me.

Thank you for the tip. This would definitely help with future challenges!:grin:

Your syntax is not compatible to when I use it in FCC. Do you know if that is due to FCC intentionally training JavaScript before the update?

Also .shift() in your example appears to be irrelevant. Here’s what I got.

function destroyer(arr) {
var args = Array.prototype.slice.call(arguments);

return arr.filter(function(n) {
return args.indexOf(n) === -1;
});
return args;
}

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


Right on. Your code looks great.