mergeSort function for stableSort.
@private
@function mergeSort
@param {ArrayLike} array
@param {Function} comparefn
@returns {Array}
760806
function mergeSort(array, comparefn) {
        var length = array.length,
            middle,
            front,
            back,
            val;

        if (length < 2) {
            val = $slice(array);
        } else {
            middle = ceil(length / 2);
            front = $slice(array, 0, middle);
            back = $slice(array, middle);
            val = merge(mergeSort(front, comparefn), mergeSort(back, comparefn), comparefn);
        }

        return val;
    }
155896
function merge() {
	return Array.from(arguments)
		.reduce((result, current) => {
			Array.from(current)
				.forEach((value, index) => {
					result[index] = result[index] && typeof result[index] !== 'boolean' ? result[index] : value;
				});

			return result;
		}, []);
}
1003040
public static <T> Iterator<T> merge(Comparator<T> comp, Iterator<T>... iterators)
    {
        switch (iterators.length)
        {
            case 0:
                throw new IllegalArgumentException("no iterables");
            case 1:
                return iterators[0];
            case 2:
                return new IteratorImpl<>(comp, iterators[0], iterators[1]);
            default:
                return new IteratorImpl<>(comp, iterators[0], merge(comp, Arrays.copyOfRange(iterators, 1, iterators.length)));
        }
    }
1259956
private static <T extends Comparable<? super T>> void sort(T[] a, int n) {
        int inc = 1;
        do {
            inc *= 3;
            inc++;
        } while (inc <= n);

        do {
            inc /= 3;
            for (int i = inc; i < n; i++) {
                T v = a[i];
                int j = i;
                while (a[j - inc].compareTo(v) < 0) {
                    a[j] = a[j - inc];
                    j -= inc;
                    if (j < inc) {
                        break;
                    }
                }
                a[j] = v;
            }
        } while (inc > 1);
    }
57304
@SafeVarargs
    public static <V extends Comparable<V>> V[] sort(V... array) {
        Arrays.sort(array);
        return array;
    }
865277
function arrayIndexOfComparer(array, item, comparer) {
    for (var i = 0, len = array.length; i < len; i++) {
      if (comparer(array[i], item)) { return i; }
    }
    return -1;
  }
1031201
function defSortFn (a, b) {
    const a1 = `${a}`;
    const b1 = `${b}`;
    if (a1 < b1) {
        return -1;
    }
    if (a1 > b1) {
        return 1;
    }
    return 0;
}
1199625
function stableSort(arr, sortFunction) {
	var length = arr.length,
		i;

	// Add index to each item
	for (i = 0; i < length; i++) {
		arr[i].ss_i = i; // stable sort index
	}

	arr.sort(function (a, b) {
		var sortValue = sortFunction(a, b);
		return sortValue === 0 ? a.ss_i - b.ss_i : sortValue;
	});

	// Remove index from items
	for (i = 0; i < length; i++) {
		delete arr[i].ss_i; // stable sort index
	}
}
577481
function sort(array, compare) {
  for (var i = 1; i < array.length; i++) {
    var item = array[i];
    var indexHole = i;
    while (indexHole > 0 && compare(array[indexHole - 1], item) > 0) {
      array[indexHole] = array[--indexHole];
    }
    array[indexHole] = item;
    if (sortExternal.shiftObserver) {
      sortExternal.shiftObserver(i, indexHole);
    }
  }

  return array;
}
1160798
function orderBy (arr) {
  var comparator = null
  var sortKeys
  arr = util.convertArray(arr)

  // determine order (last argument)
  var args = util.toArray(arguments, 1)
  var order = args[args.length - 1]
  if (typeof order === 'number') {
    order = order < 0 ? -1 : 1
    args = args.length > 1 ? args.slice(0, -1) : args
  } else {
    order = 1
  }

  // determine sortKeys & comparator
  var firstArg = args[0]
  if (!firstArg) {
    return arr
  } else if (typeof firstArg === 'function') {
    // custom comparator
    comparator = function (a, b) {
      return firstArg(a, b) * order
    }
  } else {
    // string keys. flatten first
    sortKeys = Array.prototype.concat.apply([], args)
    comparator = function (a, b, i) {
      i = i || 0
      return i >= sortKeys.length - 1
        ? baseCompare(a, b, i)
        : baseCompare(a, b, i) || comparator(a, b, i + 1)
    }
  }

  function baseCompare (a, b, sortKeyIndex) {
    var sortKey = sortKeys[sortKeyIndex]
    if (sortKey) {
      if (sortKey !== '$key') {
        if (util.isObject(a) && '$value' in a) a = a.$value
        if (util.isObject(b) && '$value' in b) b = b.$value
      }
      a = util.isObject(a) ? util.getPath(a, sortKey) : a
      b = util.isObject(b) ? util.getPath(b, sortKey) : b
    }
    return a === b ? 0 : a > b ? order : -order
  }

  // sort on a copy to avoid mutating original array
  return arr.slice().sort(comparator)
}
310834
function merge(a, b) {

    /* result set */
    var c = [];

    /* as long as there are elements in the arrays to be merged */
    while (a.length > 0 || b.length > 0) {

      /* are there elements to be merged, if yes, compare them and merge */
      var n = a.length > 0 && b.length > 0 ? a[0] < b[0] ? a.shift() : b.shift() : b.length > 0 ? b.shift() : a.length > 0 ? a.shift() : null;

      /* always push the smaller one onto the result set */
      if (n !== null) {
        c.push(n);
      }
    }
    return c;
  }
1280356
function sortCompare (x, y) {
  // 1. If x and y are both undefined, return +0.
  if (x === undefined && y === undefined) {
    return 0;
  }

  // 2. If x is undefined, return 1.
  if (x === undefined) {
    return 1;
  }

  // 3. If y is undefined, return -1.
  if (y === undefined) {
    return -1;
  }

  // 5. Let xString be ? ToString(x).
  x = String(x);

  // 6. Let yString be ? ToString(y).
  y = String(y);

  // 7. Let xSmaller be the result of performing Abstract Relational
  //    Comparison xString < yString.
  // 8. If xSmaller is true, return -1.
  // 9. Let ySmaller be the result of performing Abstract Relational
  //    Comparison yString < xString.
  // 10. If ySmaller is true, return 1.
  // 11. Return +0.
  return (x < y) ? -1 : (x > y) ? 1 : 0;
}
408013
function createMergedResultFunction(one, two) {
    return function mergedResult() {
      var a = one.apply(this, arguments);
      var b = two.apply(this, arguments);
      if (a == null) {
        return b;
      } else if (b == null) {
        return a;
      }
      var c = {};
      mergeIntoWithNoDuplicateKeys(c, a);
      mergeIntoWithNoDuplicateKeys(c, b);
      return c;
    };
  }
258024
function mergeOne(dst, src) {
  if (src === undefined) return dst;

  // According to specification arrays must be concatenated.
  // Also, the '.concat' creates a new array instance. Overrides the 'dst'.
  if (isArray(src)) return (isArray(dst) ? dst : []).concat(src);

  // Now deal with non plain 'src' object. 'src' overrides 'dst'
  // Note that functions are also assigned! We do not deep merge functions.
  if (!isPlainObject(src)) return src;

  // See if 'dst' is allowed to be mutated.
  // If not - it's overridden with a new plain object.
  var returnValue = isObject(dst) ? dst : {};

  var keys = Object.keys(src);
  for (var i = 0; i < keys.length; i += 1) {
    var key = keys[i];

    var srcValue = src[key];
    // Do not merge properties with the 'undefined' value.
    if (srcValue !== undefined) {
      var dstValue = returnValue[key];
      // Recursive calls to mergeOne() must allow only plain objects or arrays in dst
      var newDst = isPlainObject(dstValue) || isArray(srcValue) ? dstValue : {};

      // deep merge each property. Recursion!
      returnValue[key] = mergeOne(newDst, srcValue);
    }
  }

  return returnValue;
}
213788
function sort(array, maxValue) {
  var buckets = new Array(maxValue + 1);
  var sortedIndex = 0;
  var i;

  for (i = 0; i < array.length; i++) {
    if (!buckets[array[i]]) {
      buckets[array[i]] = 0;
    }
    buckets[array[i]]++;
  }

  for (i = 0; i < buckets.length; i++) {
    while (buckets[i] > 0) {
      array[sortedIndex++] = i;
      buckets[i]--;
    }
  }

  return array;
}
578465
function _mergeArrayInPlace(a,b)
{
  if ( !b || b.length === 0 )
    return;

  b.forEach(function(val) {
    if ( a.indexOf(val) === -1 )
      a.push(val);
  });
}
185684
function sort(values, boxes, indices, left, right) {
    if (left >= right) return;

    const pivot = values[(left + right) >> 1];
    let i = left - 1;
    let j = right + 1;

    while (true) {
        do i++; while (values[i] < pivot);
        do j--; while (values[j] > pivot);
        if (i >= j) break;
        swap(values, boxes, indices, i, j);
    }

    sort(values, boxes, indices, left, j);
    sort(values, boxes, indices, j + 1, right);
}