| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | var arrayEachRight = require('./_arrayEachRight'), |
| 2 | baseEachRight = require('./_baseEachRight'), |
| 3 | castFunction = require('./_castFunction'), |
| 4 | isArray = require('./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 | * @see _.forEach |
| 19 | * @example |
| 20 | * |
| 21 | * _.forEachRight([1, 2], function(value) { |
| 22 | * console.log(value); |
| 23 | * }); |
| 24 | * // => Logs `2` then `1`. |
| 25 | */ |
| 26 | function forEachRight(collection, iteratee) { |
| 27 | var func = isArray(collection) ? arrayEachRight : baseEachRight; |
| 28 | return func(collection, castFunction(iteratee)); |
| 29 | } |
| 30 | |
| 31 | module.exports = forEachRight; |