Skip to content

Commit

Permalink
fixed lodash#5818
Browse files Browse the repository at this point in the history
  • Loading branch information
Abinash Nahak committed Feb 14, 2024
1 parent c7c70a7 commit 112945a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/.internal/baseSum.ts
Expand Up @@ -7,15 +7,15 @@
* @returns {number} Returns the sum.
*/
function baseSum(array, iteratee) {
let result
let result;

for (const value of array) {
const current = iteratee(value)
if (current !== undefined) {
result = result === undefined ? current : (result + current)
const current = iteratee(value);
if (typeof current === 'number' && !isNaN(current)) {
result = result === undefined ? current : (result + current);
}
}
return result
return result;
}

export default baseSum
export default baseSum;
5 changes: 3 additions & 2 deletions src/sumBy.ts
Expand Up @@ -18,7 +18,8 @@ import baseSum from './.internal/baseSum.js';
* // => 20
*/
function sumBy(array, iteratee) {
return array != null && array.length ? baseSum(array, iteratee) : 0;
const result = array != null && array.length ? baseSum(array, iteratee) : 0;
return typeof result === 'number' && !isNaN(result) ? result : NaN;
}

export default sumBy;
export default sumBy;

0 comments on commit 112945a

Please sign in to comment.