Seek and destroy - Understanding Arguments

Seek and destroy - Understanding Arguments
0

#1

I solved the seek and destroy challenge, and took a look after, as I always do, at other types of solutions. I found this one:

function destroyer(arr) {
// Remove all the values
var args = Array.from(arguments);
args.slice(0,1);
return arr.filter(function(element) {
return args.indexOf(element) == -1;
});
}
destroyer([1, 2, 3, 2, 3], 2, 3);

My question is: why arr refers only to [1, 2, 3, 2, 3]? Shouldn’t it refer to [[1, 2, 3, 2, 3], 2, 3].

This is probably basic concept I’m not grasping, and I’d like to understand it before move on.

Help a newbie, please…


#2

The call below has three values being passed to the function.

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

Each of these values becomes an argument within the function, so when the function is only defined with one argument (as below):

function destroyer(arr) {

arr represents the first value passed into the function. To get any others passed, you would have to use the arguments object.