This is about Solution 2, using my name for the args variable. I don’t understand the chain that creates the variable target.
let targets = Array.from(arguments);
targets = targets.slice(1);
In Solution 2, this is chained.
let targets = Array.from(arguments).slice(1);
I thought arguments and slice would be inside the Array.from method.
let targets = Array.from(arguments.slice(1));
Why isn’t this how it works?
My solution
function destroyer(arr) {
let targets = Array.from(arguments);
targets = targets.slice(1);
//console.log(targets);
return arr.filter(value => {
return !targets.includes(value);
});
}
Solution 2
function destroyer(arr) {
var args = Array.from(arguments).slice(1);
return arr.filter(function(val) {
return !args.includes(val);
});
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.56
.
Challenge: Seek and Destroy
Link to the challenge: