mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Bump to v4.13.1.
This commit is contained in:
30
_createFind.js
Normal file
30
_createFind.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import baseIteratee from './_baseIteratee.js';
|
||||
import isArrayLike from './isArrayLike.js';
|
||||
import keys from './keys.js';
|
||||
|
||||
/**
|
||||
* Creates a `_.find` or `_.findLast` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} findIndexFunc The function to find the collection index.
|
||||
* @returns {Function} Returns the new find function.
|
||||
*/
|
||||
function createFind(findIndexFunc) {
|
||||
return function(collection, predicate, fromIndex) {
|
||||
var iterable = Object(collection);
|
||||
predicate = baseIteratee(predicate, 3);
|
||||
if (!isArrayLike(collection)) {
|
||||
var props = keys(collection);
|
||||
}
|
||||
var index = findIndexFunc(props || collection, function(value, key) {
|
||||
if (props) {
|
||||
key = value;
|
||||
value = iterable[key];
|
||||
}
|
||||
return predicate(value, key, iterable);
|
||||
}, fromIndex);
|
||||
return index > -1 ? collection[props ? props[index] : index] : undefined;
|
||||
};
|
||||
}
|
||||
|
||||
export default createFind;
|
||||
Reference in New Issue
Block a user