Javascript Array diff(a)

Description

Javascript Array diff(a)




Array.prototype.diff = function(a) {
  return this.filter(function (i) { return a.indexOf(i) < 0; });
};

Javascript Array diff(a)

Array.prototype.diff = function (a) {
    return this.filter(function (e) { return a.indexOf(e) === -1 });
};

Javascript Array diff(a)

Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
};


function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  newArr = arr2.diff(arr1);/*  w ww.  j  av  a 2s  .c  o  m*/

  return arr1.diff(arr2).concat(arr2.diff(arr1));


  //return newArr;
}

console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]));

Javascript Array diff(a)

/**/*ww  w . j  a v  a 2s .c  o m*/
 * Polyfills start here
 */

Array.prototype.diff = function(a) {
  var diffArray = []
  this.forEach(function(e, i) {
    if (e !== a[i] && e !== 0) diffArray.push(e)
  })
  return diffArray
}

Javascript Array diff(a)

Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
};

Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }/*from   ww w . ja v  a 2 s.co  m*/
    }
    return false;
};

function sym(args) {
  
   var a = args[0].diff(args[1]).concat(args[1].diff(args[0]));  
  
   var b = args[0].filter(function(n) {
     return args[1].indexOf(n) != -1;
   });
 
  return a;
}

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

Javascript Array diff(a)

Array.prototype.diff = function(a) {
    return this.filter(function(i) {return !(a.indexOf(i) > -1);});
};

Javascript Array diff(a)

// sample adjacency lists
Array.prototype.diff = function(a) {
    return this.filter(function(i) {
      return a.indexOf(i) == -1;
    });/*from w  w w .  j  av a2s .c o  m*/
};

Javascript Array diff(a)

Array.prototype.diff = function(a) {
 return this.filter(function(i) { return a.indexOf(i) < 0; });
};

Array.prototype.toUpper = function() {
 return this.map(function(x) { return x.toUpperCase(); });
}

exports.distance = function(lat1, lon1, lat2, lon2) {
 var radlat1 = Math.PI * lat1/180;
 var radlat2 = Math.PI * lat2/180;
 var radlon1 = Math.PI * lon1/180;
 var radlon2 = Math.PI * lon2/180;
 var theta = lon1-lon2;
 var radtheta = Math.PI * theta/180;
 var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
 dist = Math.acos(dist);//from   w  w w . j a  va  2s  .  c  om
 dist = dist * 180/Math.PI;
 dist = dist * 60 * 1.1515;
 return dist * 1.609344;
}



PreviousNext

Related