美文网首页
Symmetric Difference

Symmetric Difference

作者: 我想静静静静静 | 来源:发表于2018-05-06 19:29 被阅读0次

    function sym(args) {

      var arr = [];

      var answer = [];

      arr = Array.prototype.slice.call(arguments);

      answer = arr.reduce(function(a,b){  //合并数组

        return a.concat(b).filter(function(item,index,arr){  //过滤两个数组都有的项

          return a.indexOf(item) ===-1||b.indexOf(item)===-1;

        }).filter(function(item,index,arr){  //数组去重

          return arr.indexOf(item) ===index;

        });

      });

      return answer;

    }

    相关文章

      网友评论

          本文标题:Symmetric Difference

          本文链接:https://www.haomeiwen.com/subject/cmourftx.html