|
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 | |
|---|
| 1 | import { sortedLastIndexBy } from './sortedLastIndexBy.mjs';
|
|---|
| 2 | import { isNil } from '../../predicate/isNil.mjs';
|
|---|
| 3 | import { isNull } from '../../predicate/isNull.mjs';
|
|---|
| 4 | import { isSymbol } from '../../predicate/isSymbol.mjs';
|
|---|
| 5 | import { isNumber } from '../predicate/isNumber.mjs';
|
|---|
| 6 |
|
|---|
| 7 | const MAX_ARRAY_LENGTH = 4294967295;
|
|---|
| 8 | const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
|---|
| 9 | function 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 |
|
|---|
| 31 | export { sortedLastIndex };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.