SOURCE

const fn1 = (arr1, arr2) => {
    let res = []
    while(arr1.length && arr2.length){
        if(arr1[0] > arr2[0]){
            res.push(arr2.shift())
        } else {
            res.push(arr1.shift())
        }
    }
    return res.concat([...arr1], [...arr2])
}

const fn2 = (arr) => {
    let mid = arr.length/2
    if(arr.length < 2){
        return arr
    }
    let left = arr.splice(0, mid)
    return fn1(fn2(left), fn2(arr))
}

console.log(fn2([2, 1, 8, 5, 3, 6]))
console 命令行工具 X clear

                    
>
console