findLastIndex.js 1.7 KB

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