SOURCE

//求数组的最大值

function get_max(arr,left,right){
    let max_left , max_right , mid

    if(!Array.isArray(arr) ) return Error("arr isn't a Array")
    if(!arr.length) return Error("arr is empty")

    if(left === right) return arr[left]
    if(left -right <= 1){
        return Math.max(arr[left],arr[right])
    }
    
    mid =(left+right)/2 + left
    max_left = get_max(arr,left,mid)
    max_right = get_max(arr,mid+1,right)

    return Math.max(max_left,max_right)
}   

let numArr = [9,2,8,7,6,-7]

console.log(get_max(numArr,0,numArr.length-1))
console 命令行工具 X clear

                    
>
console