Nodejs Array Different diff(arr)

Here you can find the source of diff(arr)

Method Source Code

Array.prototype.diff = function (arr) {

        // Merge the arrays
        var mergedArr = this.concat(arr);

        // Get the elements which are unique in the array
        // Return the diff array
        return mergedArr.filter(function (e) {
            // Check if the element is appearing only once
            return mergedArr.indexOf(e) === mergedArr.lastIndexOf(e);
        });/*ww  w  .  ja va2 s. c  o m*/
};

Related

  1. diff(a)
    Array.prototype.diff = function(a) {
        return this.filter(function(i) {return a.indexOf(i) < 0;});
    };
    function diffArray(arr1, arr2) {
      var newArr = [];
      newArr = arr2.diff(arr1);
      return arr1.diff(arr2).concat(arr2.diff(arr1));
    console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]));
    ...
    
  2. diff(a)
    Array.prototype.diff = function(a) {
      return this.filter(function(i) {return !(a.indexOf(i) > -1);});
    };
    
  3. 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;
        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]);
    
  4. 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++) {
    ...
    
  5. diff(a, k)
    Array.prototype.diff = function (a, k) {
      return this.filter (function (i) { return a.column (k).indexOf (eval ("i." + k)) < 0; });
    };
    
  6. diff(array)
    Array.prototype.diff = function(array){
      return this.filter(function(i) {
        if(array){
          return !(array.indexOf(i) > -1)
      })
    
  7. diff(array)
    Array.prototype.diff = function(array) {
        return this.filter(function(e){
            return (array.indexOf(e) < 0 );
        });
    
  8. diff(init)
    Array.prototype.diff = function (init) {
        init = init || 0;
        var g = this;
        return this.reduce(function(prev,cur) {
            prev.push(cur - (prev.length > 0 ? g[prev.length-1] : init));
            return prev;
        },[]);
    
  9. diff(part)
    Array.prototype.diff = function(part) {
        return this.filter(function(element) {return part.indexOf(element) < 0;});
    };