Stuck at task 251

Stuck at task 251
0.0 0


I’m trying to solve this but can’t come up with a better solution using filter array to remove items.

The challenge is Seek and destroy:

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.

They want me to use filter to remove element in array but arr.filter only return item that meet one value not array.

var arr = [1,2,4,5,1,2,3,4,5];
var removeArr = [1,3,5];
var result = arr.filter(function(item){
      return item != removeArr[???];

I’ve try using iterate to iterate filter one by one but it still doesn’t work. Now, I’m stumped. Give me some hint!


How would you test whether item is in the array removeArr?



Here is a hint. The filter is going to iterate through arr and the value of item will represent each element of that array (1, 2, 4,5, …). What you want to ask is “Does item exist in removeArr?” If it does not exist, then return the value of true, so the filter keeps it in the result array. You have already learned about a JavaScript function for checking if an element exists in an array, so use it in your filter function.


I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.