quicksortInit = (array, comparatorFn) => {
  const comparator = new Comparator(comparatorFn);

  return (function quicksort(array, lo, hi) {
    while (lo < hi) {
      const p = partition(array, comparator, lo, hi);
      // Chooses only the smallest partition to use recursion on and
      // tail-optimize the other. This guarantees O(log n) space in worst case.
      if (p - lo < hi - p) {
        quicksort(array, lo, p - 1);
        lo = p + 1;
      } else {
        quicksort(array, p + 1, hi);
        hi = p - 1;
      }
    }

    return array;
  })(array, 0, array.length - 1);
}
Quicksort recursively sorts parts of the array in
O(n.lg n)