mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Bump to v3.6.0.
This commit is contained in:
26
internal/createFind.js
Normal file
26
internal/createFind.js
Normal file
@@ -0,0 +1,26 @@
|
||||
define(['./baseCallback', './baseFind', './baseFindIndex', '../lang/isArray'], function(baseCallback, baseFind, baseFindIndex, isArray) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
return createFind;
|
||||
});
|
||||
Reference in New Issue
Block a user