1 |
3a515b92
|
cagy
|
var baseFindKey = require('./_baseFindKey'),
|
2 |
|
|
baseForOwnRight = require('./_baseForOwnRight'),
|
3 |
|
|
baseIteratee = require('./_baseIteratee');
|
4 |
|
|
|
5 |
|
|
/**
|
6 |
|
|
* This method is like `_.findKey` except that it iterates over elements of
|
7 |
|
|
* a collection in the opposite order.
|
8 |
|
|
*
|
9 |
|
|
* @static
|
10 |
|
|
* @memberOf _
|
11 |
|
|
* @since 2.0.0
|
12 |
|
|
* @category Object
|
13 |
|
|
* @param {Object} object The object to inspect.
|
14 |
|
|
* @param {Function} [predicate=_.identity] The function invoked per iteration.
|
15 |
|
|
* @returns {string|undefined} Returns the key of the matched element,
|
16 |
|
|
* else `undefined`.
|
17 |
|
|
* @example
|
18 |
|
|
*
|
19 |
|
|
* var users = {
|
20 |
|
|
* 'barney': { 'age': 36, 'active': true },
|
21 |
|
|
* 'fred': { 'age': 40, 'active': false },
|
22 |
|
|
* 'pebbles': { 'age': 1, 'active': true }
|
23 |
|
|
* };
|
24 |
|
|
*
|
25 |
|
|
* _.findLastKey(users, function(o) { return o.age < 40; });
|
26 |
|
|
* // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
27 |
|
|
*
|
28 |
|
|
* // The `_.matches` iteratee shorthand.
|
29 |
|
|
* _.findLastKey(users, { 'age': 36, 'active': true });
|
30 |
|
|
* // => 'barney'
|
31 |
|
|
*
|
32 |
|
|
* // The `_.matchesProperty` iteratee shorthand.
|
33 |
|
|
* _.findLastKey(users, ['active', false]);
|
34 |
|
|
* // => 'fred'
|
35 |
|
|
*
|
36 |
|
|
* // The `_.property` iteratee shorthand.
|
37 |
|
|
* _.findLastKey(users, 'active');
|
38 |
|
|
* // => 'pebbles'
|
39 |
|
|
*/
|
40 |
|
|
function findLastKey(object, predicate) {
|
41 |
|
|
return baseFindKey(object, baseIteratee(predicate, 3), baseForOwnRight);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
module.exports = findLastKey;
|