0

I have tried the below code, but I am not getting satisfactory results.

function destroyer(arr) {
// Remove all the values

var newArray = arr.filter(function(x){

if(x == arr[0]){
 return x;
}
});
return newArray;
}

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

1 Answers1

1

The simplest one:

function without(array, exclude) {
    return array.filter(function(x) { return exclude.indexOf(x) === -1; });
}

You could use it like this: without([1,2,3,4,5], [1,2]) // returns [3,4,5]

Or you could try dealing with arguments list like this, but the idea would be the same.

Community
  • 1
  • 1
Microfed
  • 2,832
  • 22
  • 25