-
-
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
_.max and _.min may behave incorrectly if iteratee returns infinite number #2688
Comments
I think that the conditional expression after For |
I would like to fix this by generalizing function max(collection, iteratee, context) {
if (isEmpty(collection)) return;
iteratee = cb(iteratee, context);
return reduce(collection, function(memo, value) {
return iteratee(value) < iteratee(memo) ? value : memo;
});
} This would be a breaking change. |
Update: I have a "compromise" fix on a private work-in-progress branch, which implements the generalization I mentioned above and then jumps through a few additional hoops in order to keep it a non-breaking change. I'll probably publish that branch somewhere in the next month or so. |
The iteratee "swaps" the contents of the array, so
_.max
should return the smaller member:When the smaller member is
-Infinity
:Similar for
_.min
:I know which part of the code causes the bug, for example in
_.min
, it's the conditional expression after||
:But I don't know how to fix it because I can't figure out the exact intent of that expression.
The text was updated successfully, but these errors were encountered: