function binarySearch(arr, value) {
let minIndex = 0
let maxIndex = arr.length - 1
let middleValue
while (minIndex <= maxIndex) {
let middleIndex = Math.floor((minIndex + maxIndex) / 2)
middleValue = arr[middleIndex]
if (value < middleValue) {
maxIndex = middleIndex - 1
} else if (value > middleValue) {
minIndex = middleIndex + 1
} else {
return middleIndex
}
}
return -1
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。