Skip to content
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

Closed
TSteele27 opened this issue Jan 8, 2015 · 5 comments
Closed

_.reduce error #2004

TSteele27 opened this issue Jan 8, 2015 · 5 comments
Labels

Comments

@TSteele27
Copy link

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.

@michaelficarra
Copy link
Collaborator

Did you not provide an initial value for the reduction?

One would expect the function to just return an empty array

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.

@jdalton
Copy link
Contributor

jdalton commented Jan 8, 2015

LOL @michaelficarra. @TSteele27 This has been fixed in edge.

@michaelficarra
Copy link
Collaborator

@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.

@TSteele27
Copy link
Author

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.

@megawac
Copy link
Collaborator

megawac commented Jan 8, 2015

#1858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants