1 /** Used as references for the maximum length and index of an array. */
2 var MAX_ARRAY_LENGTH = 4294967295,
3 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
5 /* Built-in method references for those with the same name as other `lodash` methods. */
6 var nativeFloor = Math.floor,
10 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
11 * which invokes `iteratee` for `value` and each element of `array` to compute
12 * their sort ranking. The iteratee is invoked with one argument; (value).
15 * @param {Array} array The sorted array to inspect.
16 * @param {*} value The value to evaluate.
17 * @param {Function} iteratee The iteratee invoked per element.
18 * @param {boolean} [retHighest] Specify returning the highest qualified index.
19 * @returns {number} Returns the index at which `value` should be inserted into `array`.
21 function baseSortedIndexBy(array, value, iteratee, retHighest) {
22 value = iteratee(value);
25 high = array ? array.length : 0,
26 valIsNaN = value !== value,
27 valIsNull = value === null,
28 valIsUndef = value === undefined;
31 var mid = nativeFloor((low + high) / 2),
32 computed = iteratee(array[mid]),
33 isDef = computed !== undefined,
34 isReflexive = computed === computed;
37 var setLow = isReflexive || retHighest;
38 } else if (valIsNull) {
39 setLow = isReflexive && isDef && (retHighest || computed != null);
40 } else if (valIsUndef) {
41 setLow = isReflexive && (retHighest || isDef);
42 } else if (computed == null) {
45 setLow = retHighest ? (computed <= value) : (computed < value);
53 return nativeMin(high, MAX_ARRAY_INDEX);
56 module.exports = baseSortedIndexBy;