mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
23
.internal/baseSum.js
Normal file
23
.internal/baseSum.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* The base implementation of `sum` and `sumBy`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {number} Returns the sum.
|
||||
*/
|
||||
function baseSum(array, iteratee) {
|
||||
let result;
|
||||
let index = -1;
|
||||
const length = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
const current = iteratee(array[index]);
|
||||
if (current !== undefined) {
|
||||
result = result === undefined ? current : (result + current);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default baseSum;
|
||||
Reference in New Issue
Block a user