Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
853 bytes
|
Line | |
---|
1 | var baseIteratee = require('./_baseIteratee'),
|
---|
2 | isArrayLike = require('./isArrayLike'),
|
---|
3 | keys = require('./keys');
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Creates a `_.find` or `_.findLast` function.
|
---|
7 | *
|
---|
8 | * @private
|
---|
9 | * @param {Function} findIndexFunc The function to find the collection index.
|
---|
10 | * @returns {Function} Returns the new find function.
|
---|
11 | */
|
---|
12 | function createFind(findIndexFunc) {
|
---|
13 | return function(collection, predicate, fromIndex) {
|
---|
14 | var iterable = Object(collection);
|
---|
15 | if (!isArrayLike(collection)) {
|
---|
16 | var iteratee = baseIteratee(predicate, 3);
|
---|
17 | collection = keys(collection);
|
---|
18 | predicate = function(key) { return iteratee(iterable[key], key, iterable); };
|
---|
19 | }
|
---|
20 | var index = findIndexFunc(collection, predicate, fromIndex);
|
---|
21 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
---|
22 | };
|
---|
23 | }
|
---|
24 |
|
---|
25 | module.exports = createFind;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.