You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
function destroyer(arr) {
// arr is the first elements in the arguments
//get the rest of elements from the arguments
var args = Array.from(arguments).slice(1);
function equal(argu) { // pass the function to filter function
// if it is true, filter function will keep the element
// so we need to return false if arr contains the element
return !args.includes(argu);
}
return arr.filter(equal);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
网友评论