free code camp摧毁函数,运用到argument以及array.filter()方法

Seek and Destroy
摧毁数组

金克斯的迫击炮!

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

function destroyer(arr){
    var args=Array.prototype.slice.call(arguments,1);
    var a=arr.filter(function(item,index,array){
        return args.indexOf(item)==-1;//运用array.filter()方法最后要返回布尔值
    })
    console.log(a);
  }  
  destroyer([1, 2, 3, 1, 2, 3], 2,3)

第二种解法:

function destroyer(arr){
    var args=Array.prototype.slice.call(arguments,1);//Array.prototype.slice.call()是把argument转化为一个数组,1是slice()方法里面的起始下标
    var a=arr.filter(function(val){
        for (var i=0;i

你可能感兴趣的:(free code camp摧毁函数,运用到argument以及array.filter()方法)