Open
Conversation
Owner
|
We really gotta fix those |
10fd3a0 to
3988a67
Compare
Collaborator
Author
It'd probably be good. Want to do that afterwards? |
Collaborator
Author
|
Hmm, I can get speeds to roughly the same levels, but brings back some duplication. var createExtremumFinder = function(dir) {
return function(obj, iteratee, context) {
var keys = !isArrayLike(obj) && _.keys(obj),
length = (keys || obj).length,
result = dir * Infinity,
lastComputed = result,
index = 0, currentKey, value;
if (iteratee == null) {
for (; index < length; index++) {
currentKey = keys ? keys[index] : index;
value = obj[currentKey];
if (dir < 0 ? result > value : result < value) {
result = value;
}
}
} else {
for (; index < length; index++) {
currentKey = keys ? keys[index] : index;
value = obj[currentKey];
var computed = iteratee(value, currentKey, obj);
if ((dir < 0 ? computed > lastComputed : computed < lastComputed) || index === 0 && computed === lastComputed) {
result = value;
lastComputed = computed;
}
}
}
return result;
};
}; |
3158197 to
80a26bb
Compare
Collaborator
There was a problem hiding this comment.
is the found variable necessary? Can't you just infer it based on index
Collaborator
Author
There was a problem hiding this comment.
Well, the iteratee can return anything. So, if the first iteration returns undefined, that won't be greater than -Infinity. But, the next iteration might be equal.
80a26bb to
d7ca1c1
Compare
d7ca1c1 to
b782059
Compare
Collaborator
|
Its faster for the |
Owner
|
Rebase for a clean merge? |
Collaborator
Author
|
Edit: ha, wrong PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
http://jsperf.com/min-max-code-sharing
There's a hit on arrays without an iteratee. Looking into speeding that up, but everything else is faster.