Skip to content

Conversation

@VB5475
Copy link

@VB5475 VB5475 commented Dec 20, 2025

Description

Fixes issue #5818 where sumBy was returning a string concatenation instead of NaN when encountering non-numeric values.

Changes

  • Modified baseSum function to check if values are numbers before addition
  • Returns NaN immediately when a non-numeric value is encountered
  • Added test cases to verify the fix

Testing

  • ✅ Normal numeric sums still work correctly
  • ✅ Non-numeric values (strings, null, objects) now return NaN
  • ✅ Edge cases like Infinity, -Infinity, and undefined are handled correctly

Example

Before: _.sumBy([{ a: 1 }, { a: 'f' }, { a: null }], 'a')'1fnull'
After: _.sumBy([{ a: 1 }, { a: 'f' }, { a: null }], 'a')NaN

Fixes #5818

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method sumBy returns string

1 participant