function getIndex(arr,num){
        let start=0
        let end=arr.length-1
        while(start<=end){
            var mid=Math.floor((start+end)/2)
            if(num==arr[mid]){
                return mid
            }else if(num>arr[mid]){
                start=mid+1
            }else{
                end=mid-1
            }
        }
        return arr
    }
    var ary=[1,4,7,8,12,34,67,88,99,100]
    console.log(getIndex(ary,7))

WARRIOR
25 声望3 粉丝

« 上一篇
深拷贝copy