Seek and Destroy with filter

Seek and Destroy with filter
0.0 0

#1

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/


#2

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


#3

i did like this

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

and some other stuffs too


#4

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


#5

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


#6

@coderharshit Read about the every function.


#7

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