Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/review/binary-search-2.js
13399 views
1
function binarySearch(arr, target) {
2
let left = 0;
3
let right = arr.length - 1;
4
5
while (left <= right) {
6
let mid = Math.floor((left + right) / 2);
7
8
if (arr[mid] === target) {
9
return mid;
10
} else if (arr[mid] < target) {
11
left = mid + 1;
12
} else {
13
right = mid - 1;
14
}
15
}
16
17
return -1;
18
}
19
20