binarySearch.js 700 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.binarySearch = void 0;
  4. function binarySearch(offsets, start) {
  5. let low = 0;
  6. let high = offsets.length - 1;
  7. while (low <= high) {
  8. const mid = Math.floor((low + high) / 2);
  9. const midValue = offsets[mid];
  10. if (midValue < start) {
  11. low = mid + 1;
  12. }
  13. else if (midValue > start) {
  14. high = mid - 1;
  15. }
  16. else {
  17. low = mid;
  18. high = mid;
  19. break;
  20. }
  21. }
  22. return Math.max(Math.min(low, high, offsets.length - 1), 0);
  23. }
  24. exports.binarySearch = binarySearch;
  25. //# sourceMappingURL=binarySearch.js.map