source: node_modules/es-toolkit/dist/compat/array/sortedLastIndex.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: 971 bytes
Line 
1import { sortedLastIndexBy } from './sortedLastIndexBy.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 sortedLastIndex(array, value) {
10 if (isNil(array)) {
11 return 0;
12 }
13 let high = array.length;
14 if (!isNumber(value) || Number.isNaN(value) || high > HALF_MAX_ARRAY_LENGTH) {
15 return sortedLastIndexBy(array, value, value => value);
16 }
17 let low = 0;
18 while (low < high) {
19 const mid = (low + high) >>> 1;
20 const compute = array[mid];
21 if (!isNull(compute) && !isSymbol(compute) && compute <= value) {
22 low = mid + 1;
23 }
24 else {
25 high = mid;
26 }
27 }
28 return high;
29}
30
31export { sortedLastIndex };
Note: See TracBrowser for help on using the repository browser.