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