535f7f35379b23d37cc4580b8b9ac60b09180219
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / baseFind.js
1 /**
2  * The base implementation of methods like `_.find` and `_.findKey`, without
3  * support for iteratee shorthands, which iterates over `collection` using
4  * `eachFunc`.
5  *
6  * @private
7  * @param {Array|Object} collection The collection to search.
8  * @param {Function} predicate The function invoked per iteration.
9  * @param {Function} eachFunc The function to iterate over `collection`.
10  * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
11  * @returns {*} Returns the found element or its key, else `undefined`.
12  */
13 function baseFind(collection, predicate, eachFunc, retKey) {
14   var result;
15   eachFunc(collection, function(value, key, collection) {
16     if (predicate(value, key, collection)) {
17       result = retKey ? key : value;
18       return false;
19     }
20   });
21   return result;
22 }
23
24 module.exports = baseFind;