source: node_modules/es-toolkit/dist/compat/array/sortedIndex.mjs

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

Added visualizations

  • Property mode set to 100644
File size: 986 bytes
Line 
1import { sortedIndexBy } from './sortedIndexBy.mjs';
2import { isNil } from '../../predicate/isNil.mjs';
3import { isNull } from '../../predicate/isNull.mjs';
4import { isSymbol } from '../../predicate/isSymbol.mjs';
5import { isNumber } from '../predicate/isNumber.mjs';
6
7const MAX_ARRAY_LENGTH = 4294967295;
8const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
9function sortedIndex(array, value) {
10 if (isNil(array)) {
11 return 0;
12 }
13 let low = 0;
14 let high = array.length;
15 if (isNumber(value) && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
16 while (low < high) {
17 const mid = (low + high) >>> 1;
18 const compute = array[mid];
19 if (!isNull(compute) && !isSymbol(compute) && compute < value) {
20 low = mid + 1;
21 }
22 else {
23 high = mid;
24 }
25 }
26 return high;
27 }
28 return sortedIndexBy(array, value, value => value);
29}
30
31export { sortedIndex };
Note: See TracBrowser for help on using the repository browser.