mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Optimize _.max and _.min for gzip.
Former-commit-id: e4d6eb949824718aa967208203b7c487df7e02f5
This commit is contained in:
@@ -1888,11 +1888,19 @@
|
||||
*/
|
||||
function max(collection, callback, thisArg) {
|
||||
var computed = -Infinity,
|
||||
index = -1,
|
||||
length = collection ? collection.length : 0,
|
||||
result = computed;
|
||||
|
||||
if (callback || !isArray(collection)) {
|
||||
if (!callback && isArray(collection)) {
|
||||
var index = -1,
|
||||
length = collection.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
if (value > result) {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback = createCallback(callback, thisArg);
|
||||
|
||||
each(collection, function(value, index, collection) {
|
||||
@@ -1902,12 +1910,6 @@
|
||||
result = value;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
while (++index < length) {
|
||||
if (collection[index] > result) {
|
||||
result = collection[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1932,11 +1934,19 @@
|
||||
*/
|
||||
function min(collection, callback, thisArg) {
|
||||
var computed = Infinity,
|
||||
index = -1,
|
||||
length = collection ? collection.length : 0,
|
||||
result = computed;
|
||||
|
||||
if (callback || !isArray(collection)) {
|
||||
if (!callback && isArray(collection)) {
|
||||
var index = -1,
|
||||
length = collection.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
if (value < result) {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback = createCallback(callback, thisArg);
|
||||
|
||||
each(collection, function(value, index, collection) {
|
||||
@@ -1946,12 +1956,6 @@
|
||||
result = value;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
while (++index < length) {
|
||||
if (collection[index] < result) {
|
||||
result = collection[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user