1 /* Native method references for those with the same name as other `lodash` methods. */
2 var nativeFloor = Math.floor,
5 /** Used as references for the maximum length and index of an array. */
6 var MAX_ARRAY_LENGTH = 4294967295,
7 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
10 * This function is like `binaryIndex` except that it invokes `iteratee` for
11 * `value` and each element of `array` to compute their sort ranking. The
12 * 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 function invoked per iteration.
18 * @param {boolean} [retHighest] Specify returning the highest qualified index.
19 * @returns {number} Returns the index at which `value` should be inserted
22 function binaryIndexBy(array, value, iteratee, retHighest) {
23 value = iteratee(value);
26 high = array ? array.length : 0,
27 valIsNaN = value !== value,
28 valIsNull = value === null,
29 valIsUndef = value === undefined;
32 var mid = nativeFloor((low + high) / 2),
33 computed = iteratee(array[mid]),
34 isDef = computed !== undefined,
35 isReflexive = computed === computed;
38 var setLow = isReflexive || retHighest;
39 } else if (valIsNull) {
40 setLow = isReflexive && isDef && (retHighest || computed != null);
41 } else if (valIsUndef) {
42 setLow = isReflexive && (retHighest || isDef);
43 } else if (computed == null) {
46 setLow = retHighest ? (computed <= value) : (computed < value);
54 return nativeMin(high, MAX_ARRAY_INDEX);
57 module.exports = binaryIndexBy;