1234567891011121314151617181920212223242526272829303132
  1. var arrayEachRight = require('./_arrayEachRight'),
  2. baseEachRight = require('./_baseEachRight'),
  3. castFunction = require('./_castFunction'),
  4. isArray = require('./isArray');
  5. /**
  6. * This method is like `_.forEach` except that it iterates over elements of
  7. * `collection` from right to left.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 2.0.0
  12. * @alias eachRight
  13. * @category Collection
  14. * @param {Array|Object} collection The collection to iterate over.
  15. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  16. * @returns {Array|Object} Returns `collection`.
  17. * @see _.forEach
  18. * @example
  19. *
  20. * _.forEachRight([1, 2], function(value) {
  21. * console.log(value);
  22. * });
  23. * // => Logs `2` then `1`.
  24. */
  25. function forEachRight(collection, iteratee) {
  26. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  27. return func(collection, castFunction(iteratee));
  28. }
  29. module.exports = forEachRight;