SOURCE

//归并排序复习 8min
function sort(arr){
    let len = arr.length
    if(len<1) return arr
    let mid = len>>1
    let left = arr.slice(0,mid)
    let right = arr.slice(mid)
    return mergeSort(left,right)
}
function mergeSort(left,right){
    let res = [],i=0,j=0,len1 = left.length,len2 = right.length
    while(i<len1&&j<len2){
        res.push(left[i]>right[j]?right[j++]:left[i++])
    }
    console.log(res)
    return res.concat(i<len1?left.slice(i):right.slice(j))
}
let arr = [1,3,4,5,2,2,3,9,1]
console.log(sort(arr))
console 命令行工具 X clear

                    
>
console