8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
description:
when using _.sumBy on an array of objects with boolean values, the result is a boolean when the array contains only one item
_.sumBy
reproduction
run this code on https://playcode.io/lodash:
import _ from 'lodash'; const result = _.sumBy([{ bool: true }], 'bool'); console.log(_.VERSION); // 4.17.21 console.log(result); // expected: 1, actual: true console.log(typeof result); // expected: 'number', actual: 'boolean console.log(result === true); // expected: false, actual: true console.log(result === 1); // expected: true, actual: false
expected behaviour lodash should coerce boolean values to numbers (true → 1, false → 0) consistently, even for single-item arrays.
notes for quick fix replace
_.sumBy([{ bool: true }], 'bool')
with
_.filter([{ bool: true }], item => item.bool).length
The text was updated successfully, but these errors were encountered:
No branches or pull requests
description:
when using
_.sumBy
on an array of objects with boolean values, the result is a boolean when the array contains only one itemreproduction
run this code on https://playcode.io/lodash:
expected behaviour
lodash should coerce boolean values to numbers (true → 1, false → 0) consistently, even for single-item arrays.
notes
for quick fix replace
_.sumBy([{ bool: true }], 'bool')
with
_.filter([{ bool: true }], item => item.bool).length
The text was updated successfully, but these errors were encountered: