UNPKG

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