source: imaps-frontend/node_modules/lodash-es/_baseSortedIndex.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import baseSortedIndexBy from './_baseSortedIndexBy.js';
2import identity from './identity.js';
3import isSymbol from './isSymbol.js';
4
5/** Used as references for the maximum length and index of an array. */
6var MAX_ARRAY_LENGTH = 4294967295,
7 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
8
9/**
10 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
11 * performs a binary search of `array` to determine the index at which `value`
12 * should be inserted into `array` in order to maintain its sort order.
13 *
14 * @private
15 * @param {Array} array The sorted array to inspect.
16 * @param {*} value The value to evaluate.
17 * @param {boolean} [retHighest] Specify returning the highest qualified index.
18 * @returns {number} Returns the index at which `value` should be inserted
19 * into `array`.
20 */
21function baseSortedIndex(array, value, retHighest) {
22 var low = 0,
23 high = array == null ? low : array.length;
24
25 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
26 while (low < high) {
27 var mid = (low + high) >>> 1,
28 computed = array[mid];
29
30 if (computed !== null && !isSymbol(computed) &&
31 (retHighest ? (computed <= value) : (computed < value))) {
32 low = mid + 1;
33 } else {
34 high = mid;
35 }
36 }
37 return high;
38 }
39 return baseSortedIndexBy(array, value, identity, retHighest);
40}
41
42export default baseSortedIndex;
Note: See TracBrowser for help on using the repository browser.