mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Bump to v4.0.0.
This commit is contained in:
34
reduceRight.js
Normal file
34
reduceRight.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import arrayReduceRight from './internal/arrayReduceRight';
|
||||
import baseEachRight from './internal/baseEachRight';
|
||||
import baseIteratee from './internal/baseIteratee';
|
||||
import baseReduce from './internal/baseReduce';
|
||||
import isArray from './isArray';
|
||||
|
||||
/**
|
||||
* This method is like `_.reduce` except that it iterates over elements of
|
||||
* `collection` from right to left.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||||
* @param {*} [accumulator] The initial value.
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @example
|
||||
*
|
||||
* var array = [[0, 1], [2, 3], [4, 5]];
|
||||
*
|
||||
* _.reduceRight(array, function(flattened, other) {
|
||||
* return flattened.concat(other);
|
||||
* }, []);
|
||||
* // => [4, 5, 2, 3, 0, 1]
|
||||
*/
|
||||
function reduceRight(collection, iteratee, accumulator) {
|
||||
var func = isArray(collection) ? arrayReduceRight : baseReduce,
|
||||
initFromCollection = arguments.length < 3;
|
||||
|
||||
return func(collection, baseIteratee(iteratee, 4), accumulator, initFromCollection, baseEachRight);
|
||||
}
|
||||
|
||||
export default reduceRight;
|
||||
Reference in New Issue
Block a user