Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
787 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * A specialized version of `_.reduce` for arrays without support for
|
---|
3 | * iteratee shorthands.
|
---|
4 | *
|
---|
5 | * @private
|
---|
6 | * @param {Array} [array] The array 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 element of `array` as
|
---|
10 | * the initial value.
|
---|
11 | * @returns {*} Returns the accumulated value.
|
---|
12 | */
|
---|
13 | function arrayReduce(array, iteratee, accumulator, initAccum) {
|
---|
14 | var index = -1,
|
---|
15 | length = array == null ? 0 : array.length;
|
---|
16 |
|
---|
17 | if (initAccum && length) {
|
---|
18 | accumulator = array[++index];
|
---|
19 | }
|
---|
20 | while (++index < length) {
|
---|
21 | accumulator = iteratee(accumulator, array[index], index, array);
|
---|
22 | }
|
---|
23 | return accumulator;
|
---|
24 | }
|
---|
25 |
|
---|
26 | module.exports = arrayReduce;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.