source: node_modules/es-toolkit/dist/compat/array/findLastIndex.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const toArray = require('../_internal/toArray.js');
7const property = require('../object/property.js');
8const matches = require('../predicate/matches.js');
9const matchesProperty = require('../predicate/matchesProperty.js');
10
11function findLastIndex(arr, doesMatch = identity.identity, fromIndex = arr ? arr.length - 1 : 0) {
12 if (!arr) {
13 return -1;
14 }
15 if (fromIndex < 0) {
16 fromIndex = Math.max(arr.length + fromIndex, 0);
17 }
18 else {
19 fromIndex = Math.min(fromIndex, arr.length - 1);
20 }
21 const subArray = toArray.toArray(arr).slice(0, fromIndex + 1);
22 switch (typeof doesMatch) {
23 case 'function': {
24 return subArray.findLastIndex(doesMatch);
25 }
26 case 'object': {
27 if (Array.isArray(doesMatch) && doesMatch.length === 2) {
28 const key = doesMatch[0];
29 const value = doesMatch[1];
30 return subArray.findLastIndex(matchesProperty.matchesProperty(key, value));
31 }
32 else {
33 return subArray.findLastIndex(matches.matches(doesMatch));
34 }
35 }
36 case 'number':
37 case 'symbol':
38 case 'string': {
39 return subArray.findLastIndex(property.property(doesMatch));
40 }
41 }
42}
43
44exports.findLastIndex = findLastIndex;
Note: See TracBrowser for help on using the repository browser.