Nodejs Array Different diff(init)

Here you can find the source of diff(init)

Method Source Code

Array.prototype.diff = function (init) {
    init = init || 0;/*from w  ww .  j ava  2s.c  o  m*/
    var g = this;
    return this.reduce(function(prev,cur) {
        prev.push(cur - (prev.length > 0 ? g[prev.length-1] : init));
        return prev;
    },[]);
}

Related

  1. diff(a)
    function getSrv(name) {
      return angular.element(document.body).injector().get(name);
    function isNumeric(n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    function inArray(needle, haystack) {
        var length = haystack.length;
        for(var i = 0; i < length; i++) {
    ...
    
  2. diff(a, k)
    Array.prototype.diff = function (a, k) {
      return this.filter (function (i) { return a.column (k).indexOf (eval ("i." + k)) < 0; });
    };
    
  3. diff(arr)
    Array.prototype.diff = function (arr) {
            var mergedArr = this.concat(arr);
            return mergedArr.filter(function (e) {
                return mergedArr.indexOf(e) === mergedArr.lastIndexOf(e);
            });
    };
    
  4. diff(array)
    Array.prototype.diff = function(array){
      return this.filter(function(i) {
        if(array){
          return !(array.indexOf(i) > -1)
      })
    
  5. diff(array)
    Array.prototype.diff = function(array) {
        return this.filter(function(e){
            return (array.indexOf(e) < 0 );
        });
    
  6. diff(part)
    Array.prototype.diff = function(part) {
        return this.filter(function(element) {return part.indexOf(element) < 0;});
    };
    
  7. diff1(compare)
    Array.prototype.diff1 = function(compare) {
        return this.filter(function(elem) {return elem!=compare;})
    
  8. diffArrays(a)
    function getJSON(yourUrl) {
        var Httpreq = new XMLHttpRequest(); 
        Httpreq.open("GET", yourUrl, false);
        Httpreq.send(null);
        return Httpreq.responseText;
    Array.prototype.diffArrays = function(a) {
        return this.filter(function(i) {
            return a.indexOf(i) < 0;
    ...
    
  9. diffArray(arr1, arr2)
    function diffArray(arr1, arr2) {
      var newArr = arr1.concat(arr2);
      function checkItems(item) {
        if (arr1.indexOf(item) === -1 || arr2.indexOf(item) === -1) {
          return item;
      return newArr.filter(checkItems);
    diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);