source: node_modules/es-toolkit/dist/compat/array/find.js@ a762898

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: 876 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const iteratee = require('../util/iteratee.js');
7
8function find(source, _doesMatch = identity.identity, fromIndex = 0) {
9 if (!source) {
10 return undefined;
11 }
12 if (fromIndex < 0) {
13 fromIndex = Math.max(source.length + fromIndex, 0);
14 }
15 const doesMatch = iteratee.iteratee(_doesMatch);
16 if (!Array.isArray(source)) {
17 const keys = Object.keys(source);
18 for (let i = fromIndex; i < keys.length; i++) {
19 const key = keys[i];
20 const value = source[key];
21 if (doesMatch(value, key, source)) {
22 return value;
23 }
24 }
25 return undefined;
26 }
27 return source.slice(fromIndex).find(doesMatch);
28}
29
30exports.find = find;
Note: See TracBrowser for help on using the repository browser.