Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
909 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * The base implementation of `_.reduce` and `_.reduceRight`, without support
|
---|
3 | * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
---|
4 | *
|
---|
5 | * @private
|
---|
6 | * @param {Array|Object} collection The collection to iterate over.
|
---|
7 | * @param {Function} iteratee The function invoked per iteration.
|
---|
8 | * @param {*} accumulator The initial value.
|
---|
9 | * @param {boolean} initAccum Specify using the first or last element of
|
---|
10 | * `collection` as the initial value.
|
---|
11 | * @param {Function} eachFunc The function to iterate over `collection`.
|
---|
12 | * @returns {*} Returns the accumulated value.
|
---|
13 | */
|
---|
14 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
|
---|
15 | eachFunc(collection, function(value, index, collection) {
|
---|
16 | accumulator = initAccum
|
---|
17 | ? (initAccum = false, value)
|
---|
18 | : iteratee(accumulator, value, index, collection);
|
---|
19 | });
|
---|
20 | return accumulator;
|
---|
21 | }
|
---|
22 |
|
---|
23 | module.exports = baseReduce;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.