1 var baseSortedIndexBy = require('./_baseSortedIndexBy'),
2 identity = require('./identity');
4 /** Used as references for the maximum length and index of an array. */
5 var MAX_ARRAY_LENGTH = 4294967295,
6 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
9 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
10 * performs a binary search of `array` to determine the index at which `value`
11 * should be inserted into `array` in order to maintain its sort order.
14 * @param {Array} array The sorted array to inspect.
15 * @param {*} value The value to evaluate.
16 * @param {boolean} [retHighest] Specify returning the highest qualified index.
17 * @returns {number} Returns the index at which `value` should be inserted
20 function baseSortedIndex(array, value, retHighest) {
22 high = array ? array.length : low;
24 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
26 var mid = (low + high) >>> 1,
27 computed = array[mid];
29 if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
37 return baseSortedIndexBy(array, value, identity, retHighest);
40 module.exports = baseSortedIndex;