美文网首页
Diff Two Arrays

Diff Two Arrays

作者: yyggfffg | 来源:发表于2018-04-29 11:14 被阅读0次

比较两个数组,然后返回一个新数组,该数组的元素为两个给定数组中所有独有的数组元素。换言之,返回两个数组的差异。

function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  var arr3=[];
  for(var i=0;i<arr1.length;i++){
    if(arr2.indexOf(arr1[i])===-1){
      arr3.push(arr1[i]);
    }
  }
  var arr4=[];
  for(var j=0;j<arr2.length;j++){
    if(arr1.indexOf(arr2[j])===-1){
      arr4.push(arr2[j]);
    }
  }
  newArr=arr3.concat(arr4);
  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);

相关文章

  • Diff Two Arrays

    比较两个数组,然后返回一个新数组,该数组的元素为两个给定数组中所有独有的数组元素。换言之,返回两个数组的差异。

  • Diff Two Arrays

    题目 Compare two arrays and return a new array with any ite...

  • Diff Two Arrays - freeCodeCamp

    比较两个数组,然后返回一个新数组,该数组的元素为两个给定数组中所有独有的数组元素。换言之,返回两个数组的差异。 这...

  • FCC 题目 Diff Two Arrays

    题目要求 比较两个数组,然后返回一个新数组,该数组的元素为两个给定数组中所有独有的数组元素。换言之,返回两个数组的...

  • FCC之Diff Two Arrays

    最近开始跟着FreeCodeCamp自学js,因为之前Android开发过程中经常接触前端内容,感觉上面的学习节奏...

  • (待完成)LeetCode - 4

    Median of Two Sorted Arrays There are two sorted arrays n...

  • 350. Intersection of Two Arrays

    Intersection of Two Arrays IIGiven two arrays, write a fu...

  • LeetCode Problem No.4

    Median of Two Sorted Arrays There are two sorted arrays n...

  • 004- Median of Two Sorted Arrays

    Median of Two Sorted Arrays There are two sorted arrays n...

  • leetcode4

    Median of Two Sorted Arrays There are two sorted arrays n...

网友评论

      本文标题:Diff Two Arrays

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