摧毁数组

问题描述:

实现一个摧毁(destroyer)函数,第一个参数是待摧毁的数组,其余的参数是待摧毁的值。

参考:

Arguments object
Array.filter()

解决方法:

function destroyer() {
  var arr = arguments[0];
  var b = Array.prototype.slice.call(arguments, 1); // 取出剩余参数组成的数组

  // var [arr, ...b] = arguments; // 结构赋值
  return arr.filter(function(val){
    return !b.includes(val);
  });
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3); // [1, 1]
原文地址:https://www.cnblogs.com/codebook/p/13187128.html