function heapifyUp(array, compare) {

    /*
     * `currentIndex` is used to traverse the array. It starts at the last item
     * in the array and moves to the first item (the heap root).
     */
    let currentIndex = array.length - 1;

    /*
     * This loop continues so long as `currentIndex` is not the heap root (in
     * position 0). When `currentIndex` is 0, it means the path from the last
     * inserted value to the heap root is correct.
     */
    while (currentIndex > 0) {

        // get the index of this value's parent so we can get the value
        let parentIndex = getParentIndex(currentIndex);

        /*
         * If the value of the parent should come after the current value
         * (pointed to by `currentIndex`), then swap the two values so they
         * are in the correct order. Note that any value returned from the
         * comparator that is greater than zero means that the parent value
         * should come after the current value.
         */
        if (compare(array[parentIndex], array[currentIndex]) > 0) {
            swap(array, parentIndex, currentIndex);

            // move the current index to the parent so the loop can continue
            currentIndex = parentIndex;
        } else {

            /*
             * If we've reached here then the parent and current values are
             * already in the correct order. We can infer that this means
             * the rest of the path up to the root is also in the correct order
             * and so we can safely exit the loop.
             */
            break;
        }
    }
}
Normalizes the heap by starting with the last inserted item and ensuring
the entire path up to the heap root is in the correct order.
@param {Array} array The array to adjust. 
@param {Function} compare The comparator to use on values in the array. 
@returns {void}
@private