|
Last change
on this file since a762898 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 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const identity = require('../../function/identity.js');
|
|---|
| 6 | const toArray = require('../_internal/toArray.js');
|
|---|
| 7 | const property = require('../object/property.js');
|
|---|
| 8 | const matches = require('../predicate/matches.js');
|
|---|
| 9 | const matchesProperty = require('../predicate/matchesProperty.js');
|
|---|
| 10 |
|
|---|
| 11 | function 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 |
|
|---|
| 44 | exports.findLastIndex = findLastIndex;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.