Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #5818 #5819

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/.internal/baseSum.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;