a05ba7d3e7af4b00aee8102fd264dda874cbbeb8
[yaffs-website] / node_modules / uncss / node_modules / lodash / findIndex.js
1 var baseFindIndex = require('./internal/baseFindIndex'),
2     baseIteratee = require('./internal/baseIteratee');
3
4 /**
5  * This method is like `_.find` except that it returns the index of the first
6  * element `predicate` returns truthy for instead of the element itself.
7  *
8  * @static
9  * @memberOf _
10  * @category Array
11  * @param {Array} array The array to search.
12  * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
13  * @returns {number} Returns the index of the found element, else `-1`.
14  * @example
15  *
16  * var users = [
17  *   { 'user': 'barney',  'active': false },
18  *   { 'user': 'fred',    'active': false },
19  *   { 'user': 'pebbles', 'active': true }
20  * ];
21  *
22  * _.findIndex(users, function(o) { return o.user == 'barney'; });
23  * // => 0
24  *
25  * // using the `_.matches` iteratee shorthand
26  * _.findIndex(users, { 'user': 'fred', 'active': false });
27  * // => 1
28  *
29  * // using the `_.matchesProperty` iteratee shorthand
30  * _.findIndex(users, ['active', false]);
31  * // => 0
32  *
33  * // using the `_.property` iteratee shorthand
34  * _.findIndex(users, 'active');
35  * // => 2
36  */
37 function findIndex(array, predicate) {
38   return (array && array.length)
39     ? baseFindIndex(array, baseIteratee(predicate, 3))
40     : -1;
41 }
42
43 module.exports = findIndex;