source: node_modules/es-toolkit/dist/compat/array/lastIndexOf.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: 774 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isArrayLike = require('../predicate/isArrayLike.js');
6
7function lastIndexOf(array, searchElement, fromIndex) {
8 if (!isArrayLike.isArrayLike(array) || array.length === 0) {
9 return -1;
10 }
11 const length = array.length;
12 let index = fromIndex ?? length - 1;
13 if (fromIndex != null) {
14 index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1);
15 }
16 if (Number.isNaN(searchElement)) {
17 for (let i = index; i >= 0; i--) {
18 if (Number.isNaN(array[i])) {
19 return i;
20 }
21 }
22 }
23 return Array.from(array).lastIndexOf(searchElement, index);
24}
25
26exports.lastIndexOf = lastIndexOf;
Note: See TracBrowser for help on using the repository browser.