9957bbfe2801fafd73a23e68d35098372ccd227f
[yaffs-website] / node_modules / uncss / node_modules / lodash / findLastIndex.js
1 var baseFindIndex = require('./internal/baseFindIndex'),
2     baseIteratee = require('./internal/baseIteratee');
3
4 /**
5  * This method is like `_.findIndex` except that it iterates over elements
6  * of `collection` from right to left.
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': true },
18  *   { 'user': 'fred',    'active': false },
19  *   { 'user': 'pebbles', 'active': false }
20  * ];
21  *
22  * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
23  * // => 2
24  *
25  * // using the `_.matches` iteratee shorthand
26  * _.findLastIndex(users, { 'user': 'barney', 'active': true });
27  * // => 0
28  *
29  * // using the `_.matchesProperty` iteratee shorthand
30  * _.findLastIndex(users, ['active', false]);
31  * // => 2
32  *
33  * // using the `_.property` iteratee shorthand
34  * _.findLastIndex(users, 'active');
35  * // => 0
36  */
37 function findLastIndex(array, predicate) {
38   return (array && array.length)
39     ? baseFindIndex(array, baseIteratee(predicate, 3), true)
40     : -1;
41 }
42
43 module.exports = findLastIndex;