lodash icon indicating copy to clipboard operation
lodash copied to clipboard

`meanBy` returning `NaN` on empty lists is error prone

Open tran-simon opened this issue 7 months ago • 0 comments

_.meanBy([], 'test') will return NaN

This behavior is not currently documented, meaning that users might not know that it could return NaN.

Possible solutions:

  • Make meanBy return undefined instead of NaN, meaning that users using TypeScript will have to handle that case
  • Improve the documentation to warn users that they mustn't assume that the returned value is a valid number

tran-simon avatar Jul 10 '24 16:07 tran-simon