Seek and Destroy for loop inside filter

Seek and Destroy for loop inside filter
0.0 0

#1

Tell us what’s happening:
Hiya! Technically, my solution to the challenge works, however I don’t feel it’s a “true” solution but rather kind of clumsy/hacky because the function does not adjust for a variable number of arguments. Would a for loop nested inside filter accomplish this? I am thinking I need to iterate through the remaing arguments, beginning at index 1, and compare with el. Is it possible to use a for loop and filter together for this challenge? I’m attempting to not look at other code, so if anyone could help explain the logic of doing/not doing so it would be mucho appreciated.

Your code so far

function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArray=args[0].filter(function(el){
    return el!==args[1]&& el!==args[2]&&el!==args[3];
    });
    return newArray;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:


#3

Helpful as always; thanks again! Wouldn’t defining three arguments in the rest array limit us to only those three arguments though? What if we had, say, 100 arguments?


#5

Bingo. Thanks again for all your help!