mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Optimize _.reduce and _.reduceRight.
This commit is contained in:
@@ -6641,8 +6641,10 @@
|
|||||||
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function reduce(collection, iteratee, accumulator, thisArg) {
|
function reduce(collection, iteratee, accumulator, thisArg) {
|
||||||
var func = isArray(collection) ? arrayReduce : baseReduce;
|
var initFromArray = arguments.length < 3;
|
||||||
return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
|
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
|
||||||
|
? arrayReduce(collection, iteratee, accumulator, initFromArray)
|
||||||
|
: baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, baseEach);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6668,8 +6670,10 @@
|
|||||||
* // => [4, 5, 2, 3, 0, 1]
|
* // => [4, 5, 2, 3, 0, 1]
|
||||||
*/
|
*/
|
||||||
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
||||||
var func = isArray(collection) ? arrayReduceRight : baseReduce;
|
var initFromArray = arguments.length < 3;
|
||||||
return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
|
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
|
||||||
|
? arrayReduceRight(collection, iteratee, accumulator, initFromArray)
|
||||||
|
: baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, baseEachRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user