| 1 |
var baseIteratee = require('./_baseIteratee'), |
| 2 |
isArrayLike = require('./isArrayLike'), |
| 3 |
keys = require('./keys'); |
| 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 |
module.exports = createFind; |