main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
598 bytes
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * The base implementation of `_.sum` and `_.sumBy` 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 | * @returns {number} Returns the sum.
|
---|
| 9 | */
|
---|
| 10 | function baseSum(array, iteratee) {
|
---|
| 11 | var result,
|
---|
| 12 | index = -1,
|
---|
| 13 | length = array.length;
|
---|
| 14 |
|
---|
| 15 | while (++index < length) {
|
---|
| 16 | var current = iteratee(array[index]);
|
---|
| 17 | if (current !== undefined) {
|
---|
| 18 | result = result === undefined ? current : (result + current);
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | return result;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | export default baseSum;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.