UI for Zipcoin Blue

findLastKey.js 1.3KB

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