findLast.js 753 B

1234567891011121314151617181920212223242526
  1. var createFind = require('./_createFind'),
  2. findLastIndex = require('./findLastIndex');
  3. /**
  4. * This method is like `_.find` except that it iterates over elements of
  5. * `collection` from right to left.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 2.0.0
  10. * @category Collection
  11. * @param {Array|Object} collection The collection to search.
  12. * @param {Array|Function|Object|string} [predicate=_.identity]
  13. * The function invoked per iteration.
  14. * @param {number} [fromIndex=collection.length-1] The index to search from.
  15. * @returns {*} Returns the matched element, else `undefined`.
  16. * @example
  17. *
  18. * _.findLast([1, 2, 3, 4], function(n) {
  19. * return n % 2 == 1;
  20. * });
  21. * // => 3
  22. */
  23. var findLast = createFind(findLastIndex);
  24. module.exports = findLast;