1 var baseFindIndex = require('./_baseFindIndex'),
2 baseIteratee = require('./_baseIteratee'),
3 toInteger = require('./toInteger');
5 /* Built-in method references for those with the same name as other `lodash` methods. */
6 var nativeMax = Math.max,
10 * This method is like `_.findIndex` except that it iterates over elements
11 * of `collection` from right to left.
17 * @param {Array} array The array to inspect.
18 * @param {Function} [predicate=_.identity] The function invoked per iteration.
19 * @param {number} [fromIndex=array.length-1] The index to search from.
20 * @returns {number} Returns the index of the found element, else `-1`.
24 * { 'user': 'barney', 'active': true },
25 * { 'user': 'fred', 'active': false },
26 * { 'user': 'pebbles', 'active': false }
29 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
32 * // The `_.matches` iteratee shorthand.
33 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
36 * // The `_.matchesProperty` iteratee shorthand.
37 * _.findLastIndex(users, ['active', false]);
40 * // The `_.property` iteratee shorthand.
41 * _.findLastIndex(users, 'active');
44 function findLastIndex(array, predicate, fromIndex) {
45 var length = array == null ? 0 : array.length;
49 var index = length - 1;
50 if (fromIndex !== undefined) {
51 index = toInteger(fromIndex);
53 ? nativeMax(length + index, 0)
54 : nativeMin(index, length - 1);
56 return baseFindIndex(array, baseIteratee(predicate, 3), index, true);
59 module.exports = findLastIndex;