time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

find.js (1304B)


      1 var createFind = require('./_createFind'),
      2     findIndex = require('./findIndex');
      3 
      4 /**
      5  * Iterates over elements of `collection`, returning the first element
      6  * `predicate` returns truthy for. The predicate is invoked with three
      7  * arguments: (value, index|key, collection).
      8  *
      9  * @static
     10  * @memberOf _
     11  * @since 0.1.0
     12  * @category Collection
     13  * @param {Array|Object} collection The collection to inspect.
     14  * @param {Function} [predicate=_.identity] The function invoked per iteration.
     15  * @param {number} [fromIndex=0] The index to search from.
     16  * @returns {*} Returns the matched element, else `undefined`.
     17  * @example
     18  *
     19  * var users = [
     20  *   { 'user': 'barney',  'age': 36, 'active': true },
     21  *   { 'user': 'fred',    'age': 40, 'active': false },
     22  *   { 'user': 'pebbles', 'age': 1,  'active': true }
     23  * ];
     24  *
     25  * _.find(users, function(o) { return o.age < 40; });
     26  * // => object for 'barney'
     27  *
     28  * // The `_.matches` iteratee shorthand.
     29  * _.find(users, { 'age': 1, 'active': true });
     30  * // => object for 'pebbles'
     31  *
     32  * // The `_.matchesProperty` iteratee shorthand.
     33  * _.find(users, ['active', false]);
     34  * // => object for 'fred'
     35  *
     36  * // The `_.property` iteratee shorthand.
     37  * _.find(users, 'active');
     38  * // => object for 'barney'
     39  */
     40 var find = createFind(findIndex);
     41 
     42 module.exports = find;