Seek and Destroy with filter

I want to solve this with filter instead of for loop i am not able to use filter need some help

function destroyer(arr, ...arg) {
let newarr=[];
var pro;
for(let j=0;j<arr.length;j++)
{
  pro=false;
for(let i=0;i<arg.length;i++)
{
  if(arr[j]!=arg[i])
  {
    pro=true;
  }
  else {pro=false;break;}
}
if(pro)
{
  newarr.push(arr[j]);
}
}
return newarr;
}

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy/

What have you tried when it comes to using a filter? What part gets you stuck?

1 Like

i did like this

let newarr=arr.filter(a=>a!=arg);

and some other stuffs too

That would compare every element of the arr array to arg, which is different logic than you are currently using.

1 Like

tell me how can i compare every element of arr with every element of arg using filter

yes i think i have to work on it :slight_smile: