Nodejs Array Merge merge(arrayB)

Here you can find the source of merge(arrayB)

Method Source Code

// [2, 3, 5].merge([3, 5, 6]) => [2, 3, 5, 6]
Array.prototype.merge = function(arrayB) {
    var arrayA = this.valueOf(), res = [], bCopy;

    res = arrayA.unite([]);//w w  w  .  j a v  a  2  s  .c o m
    bCopy = arrayB.unite([]);

    for (var i = 0; i < res.length; i++) {
        for (var j = 0; j < arrayB.length; j++) {
            if (res[i] == bCopy[j]) {
                delete bCopy[j];
                break;
            }
        }
    }

    return res.unite(bCopy);
}

Related

  1. merge( key, array )
    Array.prototype.merge = function( key, array ){
      for( var i = 0; i < this.length; i++)
        for(var j = 0; j < array.length; j++)
          if( this[i][key] == array[j][key]) {
            for( var property in array[j] )
              if( array[j].hasOwnProperty( property) && property != key)
    ...
    
  2. merge()
    Array.prototype.merge = function() {
      var l = this.length, a = [];
      for (var i=0; i<l; i++) {
        var k = this[i].length;
        for (var j=0; j<k; j++) {
          a.push(this[i][j]);
      return a;
    ...
    
  3. merge(arr)
    Array.prototype.merge = function(arr) {
        if (arr) {
            for (var i = 0; i < arr.length; ++i) {
                if (!this.contains(arr[i]))
                    this.push(arr[i]);
    
  4. merge(arr)
    Array.prototype.merge = function (arr) {
        if (arr == null || typeof(arr) == "undefined") {
            return this;
        return this.concat(arr);
    };
    
  5. merge(arra)
    Array.prototype.merge = function(arra){
        var oneArra = this;
        var twoArra = arra;
        var oneIndex = 0;
        var twoIndex = 0;
        var result = [];
        while(!(oneIndex == oneArra.length && twoIndex == twoArra.length)){
            if((oneArra[oneIndex] < twoArra[twoIndex]) || (twoIndex == twoArra.length)){
                result[result.length] = oneArra[oneIndex];
    ...
    
  6. merge(list)
    Array.prototype.merge = function(list){
        var merged = [];
        function hasnotAdded(element, index, array) {
            if(merged.some(function(e){ return e.title === element.title;})){
                return false;
            else {
                merged.push(element);
                return true;
    ...
    
  7. merge(other)
    Array.prototype.merge = function(other) {
        var that = this;
        other.forEach(function(el2) {
            if (that.every(function(el1) {
                return el1 !== el2;
            })) {
                that.push(el2);
        });
    ...
    
  8. merge(secondArray)
    Array.prototype.merge = function(secondArray){
      for (var element in secondArray){
        if(this.contains(secondArray[element])){
          continue;
        this.push(secondArray[element]);
    
  9. merge(targets, comparer, builder)
    Array.prototype.merge = function (targets, comparer, builder) {
      return this.map(function (source) {
        var target = targets.filter(function (x) { return comparer(source, x); })[0];
        return builder(source, target);
      });
    };