Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createFind.js
1 var baseCallback = require('./baseCallback'),
2     baseFind = require('./baseFind'),
3     baseFindIndex = require('./baseFindIndex'),
4     isArray = require('../lang/isArray');
5
6 /**
7  * Creates a `_.find` or `_.findLast` function.
8  *
9  * @private
10  * @param {Function} eachFunc The function to iterate over a collection.
11  * @param {boolean} [fromRight] Specify iterating from right to left.
12  * @returns {Function} Returns the new find function.
13  */
14 function createFind(eachFunc, fromRight) {
15   return function(collection, predicate, thisArg) {
16     predicate = baseCallback(predicate, thisArg, 3);
17     if (isArray(collection)) {
18       var index = baseFindIndex(collection, predicate, fromRight);
19       return index > -1 ? collection[index] : undefined;
20     }
21     return baseFind(collection, predicate, eachFunc);
22   };
23 }
24
25 module.exports = createFind;