| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isNull = require('../../predicate/isNull.js');
|
|---|
| 6 | const isUndefined = require('../../predicate/isUndefined.js');
|
|---|
| 7 | const identity = require('../function/identity.js');
|
|---|
| 8 | const isNaN = require('../predicate/isNaN.js');
|
|---|
| 9 | const isNil = require('../predicate/isNil.js');
|
|---|
| 10 | const isSymbol = require('../predicate/isSymbol.js');
|
|---|
| 11 | const iteratee = require('../util/iteratee.js');
|
|---|
| 12 |
|
|---|
| 13 | const MAX_ARRAY_LENGTH = 4294967295;
|
|---|
| 14 | const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
|
|---|
| 15 | function sortedIndexBy(array, value, iteratee$1 = identity.identity, retHighest) {
|
|---|
| 16 | if (isNil.isNil(array) || array.length === 0) {
|
|---|
| 17 | return 0;
|
|---|
| 18 | }
|
|---|
| 19 | let low = 0;
|
|---|
| 20 | let high = array.length;
|
|---|
| 21 | const iterateeFunction = iteratee.iteratee(iteratee$1);
|
|---|
| 22 | const transformedValue = iterateeFunction(value);
|
|---|
| 23 | const valIsNaN = isNaN.isNaN(transformedValue);
|
|---|
| 24 | const valIsNull = isNull.isNull(transformedValue);
|
|---|
| 25 | const valIsSymbol = isSymbol.isSymbol(transformedValue);
|
|---|
| 26 | const valIsUndefined = isUndefined.isUndefined(transformedValue);
|
|---|
| 27 | while (low < high) {
|
|---|
| 28 | let setLow;
|
|---|
| 29 | const mid = Math.floor((low + high) / 2);
|
|---|
| 30 | const computed = iterateeFunction(array[mid]);
|
|---|
| 31 | const othIsDefined = !isUndefined.isUndefined(computed);
|
|---|
| 32 | const othIsNull = isNull.isNull(computed);
|
|---|
| 33 | const othIsReflexive = !isNaN.isNaN(computed);
|
|---|
| 34 | const othIsSymbol = isSymbol.isSymbol(computed);
|
|---|
| 35 | if (valIsNaN) {
|
|---|
| 36 | setLow = retHighest || othIsReflexive;
|
|---|
| 37 | }
|
|---|
| 38 | else if (valIsUndefined) {
|
|---|
| 39 | setLow = othIsReflexive && (retHighest || othIsDefined);
|
|---|
| 40 | }
|
|---|
| 41 | else if (valIsNull) {
|
|---|
| 42 | setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
|---|
| 43 | }
|
|---|
| 44 | else if (valIsSymbol) {
|
|---|
| 45 | setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
|---|
| 46 | }
|
|---|
| 47 | else if (othIsNull || othIsSymbol) {
|
|---|
| 48 | setLow = false;
|
|---|
| 49 | }
|
|---|
| 50 | else {
|
|---|
| 51 | setLow = retHighest ? computed <= transformedValue : computed < transformedValue;
|
|---|
| 52 | }
|
|---|
| 53 | if (setLow) {
|
|---|
| 54 | low = mid + 1;
|
|---|
| 55 | }
|
|---|
| 56 | else {
|
|---|
| 57 | high = mid;
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | return Math.min(high, MAX_ARRAY_INDEX);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | exports.sortedIndexBy = sortedIndexBy;
|
|---|