Cleanup _.max and _.min.

Former-commit-id: 9688a11db3d90f6b0f4a7d6d13b4e1c6c0709870
This commit is contained in:
John-David Dalton
2012-11-06 20:22:58 -08:00
parent 265727c30f
commit 482e013887
4 changed files with 154 additions and 146 deletions

View File

@@ -481,6 +481,18 @@
}
}
/**
* Used by `_.max` and `_.min` as the default `callback` when a given
* `collection` is a string value.
*
* @private
* @param {String} value The character to inspect.
* @returns {Number} Returns the code unit of given character.
*/
function charAtCallback(value) {
return value.charCodeAt(0);
}
/**
* Used by `sortBy` to compare transformed `collection` values, stable sorting
* them in ascending order.
@@ -2127,12 +2139,10 @@
result = computed;
if (callback || !isArray(collection)) {
if (!callback && isString(collection)) {
callback = function(value) {
return value.charCodeAt(0);
};
}
callback = createCallback(callback, thisArg);
callback = !callback && isString(collection)
? charAtCallback
: createCallback(callback, thisArg);
forEach(collection, function(value, index, collection) {
var current = callback(value, index, collection);
if (current > computed) {
@@ -2175,12 +2185,10 @@
result = computed;
if (callback || !isArray(collection)) {
if (!callback && isString(collection)) {
callback = function(value) {
return value.charCodeAt(0);
};
}
callback = createCallback(callback, thisArg);
callback = !callback && isString(collection)
? charAtCallback
: createCallback(callback, thisArg);
forEach(collection, function(value, index, collection) {
var current = callback(value, index, collection);
if (current < computed) {