findLastKey.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var baseForOwnRight = require('../internal/baseForOwnRight'),
  2. createFindKey = require('../internal/createFindKey');
  3. /**
  4. * This method is like `_.findKey` except that it iterates over elements of
  5. * a collection in the opposite order.
  6. *
  7. * If a property name is provided for `predicate` the created `_.property`
  8. * style callback returns the property value of the given element.
  9. *
  10. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11. * style callback returns `true` for elements that have a matching property
  12. * value, else `false`.
  13. *
  14. * If an object is provided for `predicate` the created `_.matches` style
  15. * callback returns `true` for elements that have the properties of the given
  16. * object, else `false`.
  17. *
  18. * @static
  19. * @memberOf _
  20. * @category Object
  21. * @param {Object} object The object to search.
  22. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  23. * per iteration.
  24. * @param {*} [thisArg] The `this` binding of `predicate`.
  25. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  26. * @example
  27. *
  28. * var users = {
  29. * 'barney': { 'age': 36, 'active': true },
  30. * 'fred': { 'age': 40, 'active': false },
  31. * 'pebbles': { 'age': 1, 'active': true }
  32. * };
  33. *
  34. * _.findLastKey(users, function(chr) {
  35. * return chr.age < 40;
  36. * });
  37. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  38. *
  39. * // using the `_.matches` callback shorthand
  40. * _.findLastKey(users, { 'age': 36, 'active': true });
  41. * // => 'barney'
  42. *
  43. * // using the `_.matchesProperty` callback shorthand
  44. * _.findLastKey(users, 'active', false);
  45. * // => 'fred'
  46. *
  47. * // using the `_.property` callback shorthand
  48. * _.findLastKey(users, 'active');
  49. * // => 'pebbles'
  50. */
  51. var findLastKey = createFindKey(baseForOwnRight);
  52. module.exports = findLastKey;