Seek and Destroy question

Hi guys,

I’m trying to understand the intermediate solution to the problem.

function destroyer(arr) {
var args = Array.from(arguments);
var test = arr.filter(function(val){
return !args.includes(val);
});
return test;
}

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

In the variable “test”, I understand that arr refers to arr[0] by default, but how does “args” work inside the filter method?

Because from my understanding, arr[0] is basically [1, 2, 3, 1, 2, 3] – but args is the whole arguments array [[1, 2, 3, 1, 2, 3], 2, 3]. How is [1, 2, 3, 1, 2, 3] not cancelled out by filter?

I hope that makes sense. Thanks in advance!

Because [1,2,3,1,2,3] is an array and arrays are hard to compare directly (open your console and type [1] == [1] and you’ll see it’s false).

Personally, I would manually exclude it from the filter, because I agree with you that it’s confusing.

Hey thanks for this! I guess slicing args would only leave it with the last 2 arrays, which is what we want to compare the first array to, which makes perfect sense.

But then… how come it still works without slicing??

it’s basically comparing args[0] with args[0], args[1], args[2], when it’s not sliced, right?