mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Bump to v3.6.0.
This commit is contained in:
25
internal/createFind.js
Normal file
25
internal/createFind.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user