348b5e8c0aabacac3d1165370dc4ae4e769f82ad
[yaffs-website] / baseSum.js
1 /**
2  * The base implementation of `_.sum` without support for iteratee shorthands.
3  *
4  * @private
5  * @param {Array} array The array to iterate over.
6  * @param {Function} iteratee The function invoked per iteration.
7  * @returns {number} Returns the sum.
8  */
9 function baseSum(array, iteratee) {
10   var result,
11       index = -1,
12       length = array.length;
13
14   while (++index < length) {
15     var current = iteratee(array[index]);
16     if (current !== undefined) {
17       result = result === undefined ? current : (result + current);
18     }
19   }
20   return result;
21 }
22
23 module.exports = baseSum;