-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
_.reduce error #2004
Comments
Did you not provide an initial value for the reduction?
No, one wouldn't. At least, no one should. The result of a reduction has nothing to do with the fact that you're reducing an array. It is only related to the initial value, the reducing function, and the array elements. |
LOL @michaelficarra. @TSteele27 This has been fixed in edge. |
@jdalton what do you mean by fixed? It returns an undefined value, no? If reduce on an effort array without an initial value returns an empty array, I will be very confused. edit: I see your link has confirmed what I thought. I wouldn't call that fixed as OP was looking for an effort array result. |
The function was part of a chain, the previous steps ended up in an empty set, so when reduce ran it threw an error complaining about an empty set, either way I don't think that throwing an error is the best way to deal with this case. This is in version 1.5.2 so it may be fixed in newer version, but I didn't see a bug report for it. |
If you try to run reduce on an empty array it will cause an error. One would expect the function to just return an empty array, not throw an error.
The text was updated successfully, but these errors were encountered: