// 二分算法实现 function binarySearch (arr, target) { let left = 0; let right = arr.length - 1; while(left <= right) { let min = parseInt((left + right) / 2); if(arr[min] == target) { return min; }else if(arr[min] < target) { left = min + 1; }else if(arr[min] > target) { right = min - 1; } } return -1; } let a = [1,2,3,4,5,6,7,8,9,10,50,59,76,100]; console.log(binarySearch(a, 59));