source: node_modules/es-toolkit/dist/compat/array/sortedIndex.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: 1.1 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const sortedIndexBy = require('./sortedIndexBy.js');
6const isNil = require('../../predicate/isNil.js');
7const isNull = require('../../predicate/isNull.js');
8const isSymbol = require('../../predicate/isSymbol.js');
9const isNumber = require('../predicate/isNumber.js');
10
11const MAX_ARRAY_LENGTH = 4294967295;
12const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
13function sortedIndex(array, value) {
14 if (isNil.isNil(array)) {
15 return 0;
16 }
17 let low = 0;
18 let high = array.length;
19 if (isNumber.isNumber(value) && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
20 while (low < high) {
21 const mid = (low + high) >>> 1;
22 const compute = array[mid];
23 if (!isNull.isNull(compute) && !isSymbol.isSymbol(compute) && compute < value) {
24 low = mid + 1;
25 }
26 else {
27 high = mid;
28 }
29 }
30 return high;
31 }
32 return sortedIndexBy.sortedIndexBy(array, value, value => value);
33}
34
35exports.sortedIndex = sortedIndex;
Note: See TracBrowser for help on using the repository browser.