396106362323752484b17b7437020a8ad72bbc7e
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / _baseSortedIndex.js
1 var baseSortedIndexBy = require('./_baseSortedIndexBy'),
2     identity = require('./identity');
3
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;
7
8 /**
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.
12  *
13  * @private
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
18  *  into `array`.
19  */
20 function baseSortedIndex(array, value, retHighest) {
21   var low = 0,
22       high = array ? array.length : low;
23
24   if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
25     while (low < high) {
26       var mid = (low + high) >>> 1,
27           computed = array[mid];
28
29       if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
30         low = mid + 1;
31       } else {
32         high = mid;
33       }
34     }
35     return high;
36   }
37   return baseSortedIndexBy(array, value, identity, retHighest);
38 }
39
40 module.exports = baseSortedIndex;