You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
610 B
23 lines
610 B
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.binarySearch = void 0; |
|
/** |
|
* Search for an item in a sorted array. |
|
* The value returned is either the position of the item or where it should be inserted. |
|
*/ |
|
function binarySearch(arr, item) { |
|
let left = 0; |
|
let right = arr.length; |
|
while (left < right) { |
|
const pos = (left + right) >> 1; |
|
if (arr[pos] < item) { |
|
left = pos + 1; |
|
} |
|
else { |
|
right = pos; |
|
} |
|
} |
|
return left; |
|
} |
|
exports.binarySearch = binarySearch; |
|
//# sourceMappingURL=search.js.map
|