the code works, but I cant wrap my head around what
“var args = Array.prototype.slice.call(arguments).slice(1)” is doing. can someone help explain this?
Your code so far
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments).slice(1);
for (i = 0; i < arr.length; i++){
for(j = 0; j < args.length; j++){
if(arr[i] === args[j]){
delete arr[i];
}
}
}
return arr.filter(Boolean);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; CrOS x86_64 10323.58.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.167 Safari/537.36.
Let me try to simplify: arguments is not an array. Slice() is an array method. To use Slice() on the arguments object we must take the arguments and pass them into the slice array method using call.
Since the call to slice returns an array, there is no need to call slice a second time.