Javascript Array diff(arr1)

Description

Javascript Array diff(arr1)


var findMissing = {
  findMissing :function (arr1,arr2){
       if(arr1.length === arr2.length) return 0;
       /*  w  w w.  jav  a  2  s. c o m*/
       if(arr1.length < arr2.length) return arr2.diff(arr1)[0];
       
       return arr1.diff(arr2)[0];
     }

};

Array.prototype.diff = function(arr1) {
    return this.filter(function(i) {return arr1.indexOf(i) < 0;});
};
module.exports = findMissing;



PreviousNext

Related