code: function heapify(array, heapSize, i, compare, swap) {
    var left = i * 2 + 1;
    var right = i * 2 + 2;
    var largest = i;
  
    if (left < heapSize && compare(array, left, largest) > 0) {
      largest = left;
    }
    if (right < heapSize && compare(array, right, largest) > 0) {
      largest = right;
    }
  
    if (largest !== i) {
      swap(array, i, largest);
      heapify(array, heapSize, largest, compare, swap);
    }
  }
docs: Heapify an array.
  @param {Array} array The array to build a heapify.
  @param {number} heapSize The size of the heap.
  @param {number} i The index of the array to heapify.
  @param {function} compare The compare function.
  @param {function} swap A function to call when the swap operation is
  performed. This can be used to listen in on internals of the algorithm.
  @returns The sorted array.