|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [a762898] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const identity = require('../../function/identity.js');
|
|---|
| 6 | const iteratee = require('../util/iteratee.js');
|
|---|
| 7 | const toInteger = require('../util/toInteger.js');
|
|---|
| 8 |
|
|---|
| 9 | function findLast(source, _doesMatch = identity.identity, fromIndex) {
|
|---|
| 10 | if (!source) {
|
|---|
| 11 | return undefined;
|
|---|
| 12 | }
|
|---|
| 13 | const length = Array.isArray(source) ? source.length : Object.keys(source).length;
|
|---|
| 14 | fromIndex = toInteger.toInteger(fromIndex ?? length - 1);
|
|---|
| 15 | if (fromIndex < 0) {
|
|---|
| 16 | fromIndex = Math.max(length + fromIndex, 0);
|
|---|
| 17 | }
|
|---|
| 18 | else {
|
|---|
| 19 | fromIndex = Math.min(fromIndex, length - 1);
|
|---|
| 20 | }
|
|---|
| 21 | const doesMatch = iteratee.iteratee(_doesMatch);
|
|---|
| 22 | if (!Array.isArray(source)) {
|
|---|
| 23 | const keys = Object.keys(source);
|
|---|
| 24 | for (let i = fromIndex; i >= 0; i--) {
|
|---|
| 25 | const key = keys[i];
|
|---|
| 26 | const value = source[key];
|
|---|
| 27 | if (doesMatch(value, key, source)) {
|
|---|
| 28 | return value;
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 | return undefined;
|
|---|
| 32 | }
|
|---|
| 33 | return source.slice(0, fromIndex + 1).findLast(doesMatch);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | exports.findLast = findLast;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.