(Seek and destroy) I have a question

Hi, I’ve completed this challenge, but it makes me wonder something.

In the line 8 of my code it displays a warning that say “Don’t make functions within a loop”.It literally took me days to realize that this wasn’t something that prevent me for passing this challenge (I never actually tried the code :sweat: ), I was so frustraiting because I couldn’t get the warning dissapear. :angry:

I know it may be stupid for the most experienced ones, but maybe for the new ones (like me) this would help too. :grimacing:

My question is, this “warning” it’s just a suggestion or it’s something to lookout when your coding?

Heré’s my code:

´ ´ ´
function destroyer(arr) {

var args = Array.from(arguments);

for (var i=1;i<args.length;i++){

  arr= arr.filter(function(val){

    return  val != args[i];
                    
  });
}

return arr;

}

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

Thanks for your answers :wink:

In this case, I think it’s just a suggestion. You would never want to put a function that isn’t a callback inside a loop.

this would have solved your warning problem, FYI.

 function destroyer(arr) {

var args = Array.from(arguments);
function outsideTheLoop(val){ return  val != args[i]; }
  
for (var i=1;i<args.length;i++){
  arr= arr.filter(outsideTheLoop);
}

return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);