美文网首页
Diff Two Arrays

Diff Two Arrays

作者: dma_master | 来源:发表于2017-08-08 06:47 被阅读14次

    题目

    Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
    Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

    Here are some helpful links:
    Comparison Operators

    Array.prototype.slice()

    Array.prototype.filter()

    Array.prototype.indexOf()

    Array.prototype.concat()

    given code

    function diffArray(arr1, arr2) {
      var newArr = [];
      // Same, same; but different.
      return newArr;
    }
    diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
    
    • 遍历arr1
    • 在遍历arr1的时候遍历arr2。比较两个元素是否全等。如果全等,那么两个元素的下标都加一,如果不等,则把

    相关文章

      网友评论

          本文标题:Diff Two Arrays

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