SOURCE

const sort = (arr = []) => {
    if (arr.length < 2) return arr

    const middle = Math.floor(arr.length / 2)
    const left = arr.slice(0, middle)
    const right = arr.slice(middle)

    const leftSort = sort(left)
    const rightSort = sort(right)
    const result = []
    while (leftSort.length && rightSort.length) {
        if (leftSort[0] <= rightSort[0]) {
            result.push(leftSort.shift())
        } else {
            result.push(rightSort.shift())
        }
    }
    return [...result, ...leftSort, ...rightSort]
}

const arr = [3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48];
console.log(sort(arr))
console 命令行工具 X clear

                    
>
console