MCPcopy
hub / github.com/lodash/lodash / baseSortedIndexBy

Function baseSortedIndexBy

lodash.js:4195–4236  ·  view source on GitHub ↗

* The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` * which invokes `iteratee` for `value` and each element of `array` to compute * their sort ranking. The iteratee is invoked with one argument; (value). * * @private * @param {Array} array The sorted arr

(array, value, iteratee, retHighest)

Source from the content-addressed store, hash-verified

4193 * into `array`.
4194 */
4195 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4196 var low = 0,
4197 high = array == null ? 0 : array.length;
4198 if (high === 0) {
4199 return 0;
4200 }
4201
4202 value = iteratee(value);
4203 var valIsNaN = value !== value,
4204 valIsNull = value === null,
4205 valIsSymbol = isSymbol(value),
4206 valIsUndefined = value === undefined;
4207
4208 while (low < high) {
4209 var mid = nativeFloor((low + high) / 2),
4210 computed = iteratee(array[mid]),
4211 othIsDefined = computed !== undefined,
4212 othIsNull = computed === null,
4213 othIsReflexive = computed === computed,
4214 othIsSymbol = isSymbol(computed);
4215
4216 if (valIsNaN) {
4217 var setLow = retHighest || othIsReflexive;
4218 } else if (valIsUndefined) {
4219 setLow = othIsReflexive && (retHighest || othIsDefined);
4220 } else if (valIsNull) {
4221 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4222 } else if (valIsSymbol) {
4223 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4224 } else if (othIsNull || othIsSymbol) {
4225 setLow = false;
4226 } else {
4227 setLow = retHighest ? (computed <= value) : (computed < value);
4228 }
4229 if (setLow) {
4230 low = mid + 1;
4231 } else {
4232 high = mid;
4233 }
4234 }
4235 return nativeMin(high, MAX_ARRAY_INDEX);
4236 }
4237
4238 /**
4239 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without

Callers 3

baseSortedIndexFunction · 0.85
sortedIndexByFunction · 0.85
sortedLastIndexByFunction · 0.85

Calls 2

isSymbolFunction · 0.85
iterateeFunction · 0.70

Tested by

no test coverage detected