artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
_baseSortedIndexBy.js
1 var isSymbol = require('./isSymbol');
2 
4 var MAX_ARRAY_LENGTH = 4294967295,
5  MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
6 
7 /* Built-in method references for those with the same name as other `lodash` methods. */
8 var nativeFloor = Math.floor,
9  nativeMin = Math.min;
10 
24 function baseSortedIndexBy(array, value, iteratee, retHighest) {
25  value = iteratee(value);
26 
27  var low = 0,
28  high = array == null ? 0 : array.length,
29  valIsNaN = value !== value,
30  valIsNull = value === null,
31  valIsSymbol = isSymbol(value),
32  valIsUndefined = value === undefined;
33 
34  while (low < high) {
35  var mid = nativeFloor((low + high) / 2),
36  computed = iteratee(array[mid]),
37  othIsDefined = computed !== undefined,
38  othIsNull = computed === null,
39  othIsReflexive = computed === computed,
40  othIsSymbol = isSymbol(computed);
41 
42  if (valIsNaN) {
43  var setLow = retHighest || othIsReflexive;
44  } else if (valIsUndefined) {
45  setLow = othIsReflexive && (retHighest || othIsDefined);
46  } else if (valIsNull) {
47  setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
48  } else if (valIsSymbol) {
49  setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
50  } else if (othIsNull || othIsSymbol) {
51  setLow = false;
52  } else {
53  setLow = retHighest ? (computed <= value) : (computed < value);
54  }
55  if (setLow) {
56  low = mid + 1;
57  } else {
58  high = mid;
59  }
60  }
61  return nativeMin(high, MAX_ARRAY_INDEX);
62 }
63 
64 module.exports = baseSortedIndexBy;