mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
26 lines
829 B
JavaScript
26 lines
829 B
JavaScript
import baseCallback from './baseCallback';
|
|
import baseFind from './baseFind';
|
|
import baseFindIndex from './baseFindIndex';
|
|
import isArray from '../lang/isArray';
|
|
|
|
/**
|
|
* Creates a `_.find` or `_.findLast` function.
|
|
*
|
|
* @private
|
|
* @param {Function} eachFunc The function to iterate over a collection.
|
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
|
* @returns {Function} Returns the new find function.
|
|
*/
|
|
function createFind(eachFunc, fromRight) {
|
|
return function(collection, predicate, thisArg) {
|
|
predicate = baseCallback(predicate, thisArg, 3);
|
|
if (isArray(collection)) {
|
|
var index = baseFindIndex(collection, predicate, fromRight);
|
|
return index > -1 ? collection[index] : undefined;
|
|
}
|
|
return baseFind(collection, predicate, eachFunc);
|
|
};
|
|
}
|
|
|
|
export default createFind;
|