main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
851 bytes
|
Line | |
---|
1 | import baseIteratee from './_baseIteratee.js';
|
---|
2 | import isArrayLike from './isArrayLike.js';
|
---|
3 | import keys from './keys.js';
|
---|
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 | export default createFind;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.