Merge two arrays
972019
function _merge_array(opts, a, b) {
	debug.assert(opts).is('object');

	var ids_mapped = {};

	var tmp = [].concat(a);

	ARRAY(a).forEach(function(v) {
		if(v && v.$id) {
			ids_mapped[v.$id] = true;
			return;
		}
	});

	ARRAY(b).forEach(function(v) {
		var id = v && v.$id;

		if(id && ids_mapped.hasOwnProperty(id)) {
			return;
		}

		if( tmp.indexOf(v) >= 0 ) {
			return;
		}

		if(id) {
			ids_mapped[id] = true;
		}

		tmp.push(v);
	});

	if(opts.cache && opts.cache._has_cursors) {
		ARRAY(tmp).forEach(function(v, i) {

			var parent;
			var key;

			key = a.indexOf(v);
			if(key >= 0) {
				parent = a;
			} else {
				key = b.indexOf(v);
				if(key >= 0) {
					parent = b;
				}
			}

			if(!(parent && (key >= 0))) {
				return;
			}

			//debug.log('Searching cursor...');
			var f = opts.cache.findCursor(parent, key);
			if(f) {
				//debug.log('Expanding cursor...');
				opts.cache.addToCursor(f, tmp, i);
			}
		});
	}

	return tmp;
}
803476
public static function merge(array ...$arrays): array
    {
        $res = array_shift($arrays);
        while (!empty($arrays)) {
            foreach (array_shift($arrays) as $key => $value) {
                if (is_int($key)) {
                    if (array_key_exists($key, $res)) {
                        $res[] = $value;
                    } else {
                        $res[$key] = $value;
                    }
                } elseif (
                    is_array($value)
                    && isset($res[$key])
                    && is_array($res[$key])
                ) {
                    $res[$key] = static::merge($res[$key], $value);
                } else {
                    $res[$key] = $value;
                }
            }
        }
        return $res;
    }
985174
function arrayMergeUnique(a, b) {
  return a.concat(b).filter(function(v,i,c) {
    if(i === c.indexOf(v)) return true
    return false
  })
}
1109985
def _merge(self, a, b):
        """"""
        for k, v in a.items():
            if isinstance(v, dict):
                item = b.setdefault(k, {})
                self._merge(v, item)
            elif isinstance(v, list):
                item = b.setdefault(k, [{}])
                if len(v) == 1 and isinstance(v[0], dict):
                    self._merge(v[0], item[0])
                else:
                    b[k] = v
            else:
                b[k] = v
        return b
1346457
function merge( a, l, m, r ) {
    const n1 = m - l + 1;
    const n2 = r - m;
    const L = a.slice( l, m + 1 );
    const R = a.slice( m + 1, 1 + r );

    let i = 0, j = 0, k = l;
    while( i < n1 && j < n2 ) {
        if( L[ i ][ 0 ] <= R[ j ][ 0 ] ) {
            a[ k ] = L[ i ];
            i++;
        } else {
            a[ k ] = R[ j ];
            j++;
        }
        k++;
    }

    while( i < n1 ) {
        a[ k ] = L[ i ];
        i++;
        k++;
    }

    while( j < n2 ) {
        a[ k ] = R[ j ];
        j++;
        k++;
    }
}
1223825
public static function Merge(array $array1 = null, array $array2 = null){

		//check for the existance of the implementation class
		self::setImplmentationClass();

		//set the input parameters in a try...catch block for better error handling
		try {

			//set the value fo the $inputArray1 parameter
			$array1 = ( ! is_null($array1)) ? $array1 : self::$ArrayHelperClassInstance->getOutputElement();
			
			//set the value fo the $inputArray2 parameter
			$array2 = ( ! is_null($array2)) ? $array2 : self::$ArrayHelperClassInstance->getOutputElement();

			//check if null was supplied for the $key parameter
			if($array === null) throw new ArrayHelperException("NULL \$array1 value passed to ArrayHelper::Merge() method which merges the elements of two arrays. A valid array1 is expected!", 1);

			//check if null value was set for the inputArray paramter
			if($array2 === null) throw new ArrayHelperException("NULL \$array2 value passed to ArrayHelper::Merge() method which merges the elements of two arrays. A valid array2 is expected!", 1);
			
			//call the implementation class to merge the input array
			self::$ArrayHelperClassInstance->Merge($array1, $array2);

			//return the static instance
			return new static;

		} 

		//catch the error messages here
		catch (ArrayHelperException $ArrayHelperExceptionInstance) {

			//diplay the error message
			$ArrayHelperExceptionInstance->errorShow();
			
		}
	}
860012
function merge() {
		var i,j,args,arg,key,result=[].splice.call(arguments, 0, 1)[0] || {};
		for (i=0; args=arguments[i]; i++) {
			if (! Array.isArray(args)) {args = [args];}
			for (j=0; arg=args[j]; j++) {
				for (key in arg) {result[key] = arg[key];}
			}
		}
		return result;
	}
295607
static function arrayMerge($array1, $array2, $overwriteValue = true)
    {
//        if($overwriteValue) {
//            foreach ($array2 as $key => $Value) {
//                if (array_key_exists($key, $array1) && is_array($Value)) {
//                    $array1[$key] = self::arrayMergeRecursively(
//                        $array1[$key], $array2[$key], $overwriteValue
//                    );
//                } else {
//                    $array1[$key] = $Value;
//                }
//            }
//        } else {
//            $array1 = array_merge_recursive($array1, $array2);
//        }

        $arrayMerged = array_merge_recursive($array1, $array2);
        $arrayUnique = array_unique($arrayMerged, SORT_STRING);

        return $arrayUnique;
    }
20529
public static function arrayMergeNoDuplicates(array &$array1, array &$array2) {
    $merged = array_merge($array1, $array2);
    $merged_without_dups = array_unique($merged);
    $merged_rekeyed = array_values($merged_without_dups);

    return $merged_rekeyed;
  }
683405
function array_merge_recursive_unique($array1, $array2)
	{
		$arrays = func_get_args();
		$narrays = count($arrays);
		$ret = $arrays[0];
		for ($i = 1; $i < $narrays; $i ++) {
			foreach ($arrays[$i] as $key => $value) {
				if (((string) $key) === ((string)((int) $key))) { // integer or string as integer key - append
					$ret[] = $value;
				} else { // string key - merge
					if (is_array($value) && isset($ret[$key])) {
						$ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
					} else {
						$ret[$key] = $value;
					}
				}
			}
		}
		return $ret;
	}
801283
function merge(Obj1, Obj2) {
    if (typeof Obj1 != 'object') {
        return {};
    }
    if (typeof Obj2 != 'object') {
        return Obj1;
    }
    for (var index in Obj2) {
        if (Obj2.hasOwnProperty(index)) {
            Obj1[index] = Obj2[index];
        }
    }

    return Obj1;
}
667002
function merge(obj1, obj2) {
  var res = {}, attrname;

  for (attrname in obj1) {
    res[attrname] = obj1[attrname];
  }
  for (attrname in obj2) {
    res[attrname] = obj2[attrname];
  }
  return res;
}
873710
function mergeDeepArrays(array1, array2) {
  const length = Math.max(array1.length, array2.length);

  let index = -1,
      mergedArray = [];

  while (++index < length) {
    if (index < array2.length) {
      mergedArray[index] = getDeeplyMergedValues(array1[index], array2[index]);

      continue;
    }

    mergedArray[index] = array1[index];
  }

  return mergedArray;
}
529662
function mergeArrays (a, b) {
    // if target is array then add b to array otherwise return undefined
    // so normal _.merge will be performed
    return Array.isArray(a) ? a.concat(b) : undefined
}
609872
function _join(arr1, arr2) {
	var len = arr1.length > arr2 ? arr1.length : arr2.length
	var joinedArr = []
	while(len --) {
		joinedArr.push(arr1.shift())
		joinedArr.push(arr2.shift())
	}
	// merge remains
	return joinedArr.concat(arr1).concat(arr2)
}
905919
protected static function arrayMerge($a, $b)
    {
        foreach ($b as $k => $v) {
            if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
                $a[$k] = $v;
            } else {
                $a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
            }
        }
        return $a;
    }
981172
def _merge_array(lhs, rhs, type_):
    """"""
    element_type = type_.array_element_type
    if element_type.code in _UNMERGEABLE_TYPES:
        # Individual values cannot be merged, just concatenate
        lhs.list_value.values.extend(rhs.list_value.values)
        return lhs
    lhs, rhs = list(lhs.list_value.values), list(rhs.list_value.values)

    # Sanity check: If either list is empty, short-circuit.
    # This is effectively a no-op.
    if not len(lhs) or not len(rhs):
        return Value(list_value=ListValue(values=(lhs + rhs)))

    first = rhs.pop(0)
    if first.HasField("null_value"):  # can't merge
        lhs.append(first)
    else:
        last = lhs.pop()
        try:
            merged = _merge_by_type(last, first, element_type)
        except Unmergeable:
            lhs.append(last)
            lhs.append(first)
        else:
            lhs.append(merged)
    return Value(list_value=ListValue(values=(lhs + rhs)))