UNPKG

@phensley/cldr-utils

Version:
25 lines 638 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Binary search the array for the element N. Return the index of the number * in the array, or the index of the number preceeding it. */ exports.binarySearch = function (nums, n) { var lo = 0; var hi = nums.length - 1; var mid = 0; while (lo <= hi) { mid = Math.floor((lo + hi) / 2); if (nums[mid] > n) { hi = mid - 1; } else if (nums[mid] < n) { lo = mid + 1; } else { return mid; } } return lo - 1; }; //# sourceMappingURL=search.js.map