-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathforEachRight.js
27 lines (25 loc) · 1.11 KB
/
forEachRight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
define(['../internal/arrayEachRight', '../internal/baseEachRight', '../internal/bindCallback', '../lang/isArray'], function(arrayEachRight, baseEachRight, bindCallback, isArray) {
/**
* This method is like `_.forEach` except that it iterates over elements of
* `collection` from right to left.
*
* @static
* @memberOf _
* @alias eachRight
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(',');
* // => logs each value from right to left and returns the array
*/
function forEachRight(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
? arrayEachRight(collection, iteratee)
: baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
}
return forEachRight;
});