-
Notifications
You must be signed in to change notification settings - Fork 7k
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
sumBy returns bool instead of integer when the result equals 1 #2058
Comments
_.sumBy([{ 'x': 1 }], 'x')
// 1 |
//list.items
//[{isNew: true}]
list.newItemCount = _.sumBy(list.items, {isNew: true});
//true
//list.items
//[{isNew: true}, {isNew: true}]
//list.newItemCount = _.sumBy(list.items, {isNew: true});
//2 |
See. next time, lead with an example :P You're using the true + true // 2 |
That's a weird behavior for "sum". So how do I count the number of occurrences of isNew: true in one line? I mean, this code was working until I updated to Lodash 4. Edit: |
_.countBy(list.items, 'isNew')['true']; // seems a bit ugly? |
Yeah, though you could do _.sumBy(list.items, _.flow(_.property('isNew'), Number)); or
Naw, it's great. I was just going to suggest it. It's also better suited for the given task. |
Cool, I guess I have to live with that from now on. |
Why is this closed as invalid? This is really counter-intuitive behavior. I can't see any reason why |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I've noticed that sumBy in Lodash 4 returns bool true instead of 1 if the sum is 1. If the sum is 2 or more it returns an integer as usual. Is this expected behavior?
The text was updated successfully, but these errors were encountered: