|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
662 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 2 |
|
|---|
| 3 | function lastIndexOf(array, searchElement, fromIndex) {
|
|---|
| 4 | if (!isArrayLike(array) || array.length === 0) {
|
|---|
| 5 | return -1;
|
|---|
| 6 | }
|
|---|
| 7 | const length = array.length;
|
|---|
| 8 | let index = fromIndex ?? length - 1;
|
|---|
| 9 | if (fromIndex != null) {
|
|---|
| 10 | index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
|
|---|
| 11 | }
|
|---|
| 12 | if (Number.isNaN(searchElement)) {
|
|---|
| 13 | for (let i = index; i >= 0; i--) {
|
|---|
| 14 | if (Number.isNaN(array[i])) {
|
|---|
| 15 | return i;
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 | return Array.from(array).lastIndexOf(searchElement, index);
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | export { lastIndexOf };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.