src/operator/merge-sort.js
function merge (arr, lo, mid, hi, sortFn) {
    const mainArr = arr;
    const auxArr = [];
    for (let i = lo; i <= hi; i += 1) {
        auxArr[i] = mainArr[i];
    }
    let a = lo;
    let b = mid + 1;

    for (let i = lo; i <= hi; i += 1) {
        if (a > mid) {
            mainArr[i] = auxArr[b];
            b += 1;
        } else if (b > hi) {
            mainArr[i] = auxArr[a];
            a += 1;
        } else if (sortFn(auxArr[a], auxArr[b]) <= 0) {
            mainArr[i] = auxArr[a];
            a += 1;
        } else {
            mainArr[i] = auxArr[b];
            b += 1;
        }
    }
}
function merge (arr, lo, mid, hi, sortFn) {
    const mainArr = arr;
    const auxArr = [];
    for (let i = lo; i <= hi; i += 1) {
        auxArr[i] = mainArr[i];
    }
    let a = lo;
    let b = mid + 1;

    for (let i = lo; i <= hi; i += 1) {
        if (a > mid) {
            mainArr[i] = auxArr[b];
            b += 1;
        } else if (b > hi) {
            mainArr[i] = auxArr[a];
            a += 1;
        } else if (sortFn(auxArr[a], auxArr[b]) <= 0) {
            mainArr[i] = auxArr[a];
            a += 1;
        } else {
            mainArr[i] = auxArr[b];
            b += 1;
        }
    }
}
function merge ( arr , lo , mid , hi , sortFn ) { const mainArr = arr ; const auxArr = [ ] ; for ( let i = lo ; i <= hi ; i += 1 ) { auxArr [ i ] = mainArr [ i ] ; } let a = lo ; let b = mid + 1 ; for ( let i = lo ; i <= hi ; i += 1 ) { if ( a > mid ) { mainArr [ i ] = auxArr [ b ] ; b += 1 ; } else if ( b > hi ) { mainArr [ i ] = auxArr [ a ] ; a += 1 ; } else if ( sortFn ( auxArr [ a ] , auxArr [ b ] ) <= 0 ) { mainArr [ i ] = auxArr [ a ] ; a += 1 ; } else { mainArr [ i ] = auxArr [ b ] ; b += 1 ; } } }
The helper function for merge sort which creates the sorted array
from the two halves of the input array.

@param {Array} arr - The target array which needs to be merged.
@param {number} lo - The starting index of the first array half.
@param {number} mid - The ending index of the first array half.
@param {number} hi - The ending index of the second array half.
@param {Function} sortFn - The sort function.
The helper function for merge sort which creates the sorted array from the two halves of the input array .