partition = (a, comparator, lo, hi) => {
  // pick a random element, swap with the rightmost and
  // use it as pivot
  swap(a, Math.floor(Math.random() * (hi - lo)) + lo, hi);
  const pivot = hi;

  // dividerPosition keeps track of the position
  // where the pivot should be inserted
  let dividerPosition = lo;

  for (let i = lo; i < hi; i++) {
    if (comparator.lessThan(a[i], a[pivot])) {
      swap(a, i, dividerPosition);
      dividerPosition++;
    }
  }
  swap(a, dividerPosition, pivot);
  return dividerPosition;
}
Chooses a pivot and makes every element that is
lower than the pivot move to its left, and every
greater element moves to its right

@return Number the positon of the pivot