|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
765 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { identity } from '../../function/identity.mjs';
|
|---|
| 2 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 3 |
|
|---|
| 4 | function find(source, _doesMatch = identity, fromIndex = 0) {
|
|---|
| 5 | if (!source) {
|
|---|
| 6 | return undefined;
|
|---|
| 7 | }
|
|---|
| 8 | if (fromIndex < 0) {
|
|---|
| 9 | fromIndex = Math.max(source.length + fromIndex, 0);
|
|---|
| 10 | }
|
|---|
| 11 | const doesMatch = iteratee(_doesMatch);
|
|---|
| 12 | if (!Array.isArray(source)) {
|
|---|
| 13 | const keys = Object.keys(source);
|
|---|
| 14 | for (let i = fromIndex; i < keys.length; i++) {
|
|---|
| 15 | const key = keys[i];
|
|---|
| 16 | const value = source[key];
|
|---|
| 17 | if (doesMatch(value, key, source)) {
|
|---|
| 18 | return value;
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 | return undefined;
|
|---|
| 22 | }
|
|---|
| 23 | return source.slice(fromIndex).find(doesMatch);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | export { find };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.