lib/array/sort.js
function partition(a, l, h, c) {
  const p = a[pivot(a, l, h, c)];

  let i = l - 1;
  let j = h + 1;

  for (;;) {
    do {
      i++;
    } while (c(a[i], p) < 0);

    do {
      j--;
    } while (c(a[j], p) > 0);

    if (i < j) {
      [a[i], a[j]] = [a[j], a[i]];
    } else {
      return j;
    }
  }
}
function partition(a, l, h, c) {
  const p = a[pivot(a, l, h, c)];

  let i = l - 1;
  let j = h + 1;

  for (;;) {
    do {
      i++;
    } while (c(a[i], p) < 0);

    do {
      j--;
    } while (c(a[j], p) > 0);

    if (i < j) {
      [a[i], a[j]] = [a[j], a[i]];
    } else {
      return j;
    }
  }
}
Partition a subarray according to the Hoare partitioning scheme.

@see https://en.wikipedia.org/wiki/Quicksort#Hoare_partition_scheme

@param {Array} a The array to partition.
@param {number} l The lower index of the partition.
@param {number} h The higher index of the partition.
@param {Function} c The comparator function.
@return {number} The final position of the pivot.
@private