source: node_modules/es-toolkit/dist/compat/array/sortedIndexBy.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.3 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isNull = require('../../predicate/isNull.js');
6const isUndefined = require('../../predicate/isUndefined.js');
7const identity = require('../function/identity.js');
8const isNaN = require('../predicate/isNaN.js');
9const isNil = require('../predicate/isNil.js');
10const isSymbol = require('../predicate/isSymbol.js');
11const iteratee = require('../util/iteratee.js');
12
13const MAX_ARRAY_LENGTH = 4294967295;
14const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
15function 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
63exports.sortedIndexBy = sortedIndexBy;
Note: See TracBrowser for help on using the repository browser.