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.
Note: You have to use the arguments object.
我们要写一个叫destroyer的函数。传给它的第一个参数是数组,我们称他为初始数组。后续的参数数量是不确定的,可能有一个或多个。你需要做的是,从初始数组中移除所有与后续参数相等的元素,并返回移除元素后的数组。
你必须使用arguments对象
function destroyer(arr) {
let arg = Array.from(arguments).slice(1)
let newArr = arr.slice();
for(let i = 0;i< arg.length;i++){
newArr = newArr.filter(val=>{
return val !== arg[i]
})
}
return newArr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
function destroyer(arr) {
let arg = Array.from(arguments).slice(1)
return arr.filter(item => !arg.includes(item))
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
本文介绍了一个名为destroyer的函数实现,该函数接受一个数组作为第一个参数,随后接收一个或多个参数。其功能是从初始数组中移除所有与这些额外参数值相同的元素,并返回处理后的数组。

被折叠的 条评论
为什么被折叠?



