-
-
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
Guard with isIterationCall #2231
base: master
Are you sure you want to change the base?
Conversation
@@ -136,15 +136,35 @@ | |||
}; | |||
}; | |||
|
|||
// Helper to determine if index is within the bounds of an array. | |||
var isIndex = function(index, length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this helper necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily, but there's a bit of duplication between isArrayLike
and isIterationCall
that'll get worse once I propose only considering ints and not floats as proper index.
@@ -330,7 +353,8 @@ | |||
_.min = function(obj, iteratee, context) { | |||
var result = Infinity, lastComputed = Infinity, | |||
value, computed; | |||
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object') && obj != null) { | |||
if (context && isIterationCall(obj, iteratee, context)) iteratee = null; | |||
if (iteratee == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a test for this change
Please explain what this is doing, beyond what the previous "guard" flag was already doing? |
It's a more thorough check for when a |
Maybe an example would help clarify? I'm don't see any changed tests in this PR. |
For future reference, |
Stolen from lodash, used to determine if one of our underscore methods were called by
_.each
,_.map
, or friends.