Permalink
Browse files

Fixes #854 -- return values for non-numeric comparisons.

  • Loading branch information...
1 parent dfb47b0 commit 3148c4f1636b6f93f313607b72ce5fd8a25f47ab @jashkenas committed Nov 12, 2012
Showing with 4 additions and 2 deletions.
  1. +2 −0 test/collections.js
  2. +2 −2 underscore.js
View
@@ -268,6 +268,7 @@ $(document).ready(function() {
equal(-Infinity, _.max({}), 'Maximum value of an empty object');
equal(-Infinity, _.max([]), 'Maximum value of an empty array');
+ equal(_.max({'a': 'a'}), -Infinity, 'Maximum value of a non-numeric collection');
equal(299999, _.max(_.range(1,300000)), "Maximum value of a too-big array");
});
@@ -280,6 +281,7 @@ $(document).ready(function() {
equal(Infinity, _.min({}), 'Minimum value of an empty object');
equal(Infinity, _.min([]), 'Minimum value of an empty array');
+ equal(_.min({'a': 'a'}), Infinity, 'Minimum value of a non-numeric collection');
var now = new Date(9999999999);
var then = new Date(0);
View
@@ -253,7 +253,7 @@
return Math.max.apply(Math, obj);
}
if (!iterator && _.isEmpty(obj)) return -Infinity;
- var result = {computed : -Infinity};
+ var result = {computed : -Infinity, value: -Infinity};
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed >= result.computed && (result = {value : value, computed : computed});
@@ -267,7 +267,7 @@
return Math.min.apply(Math, obj);
}
if (!iterator && _.isEmpty(obj)) return Infinity;
- var result = {computed : Infinity};
+ var result = {computed : Infinity, value: Infinity};
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed < result.computed && (result = {value : value, computed : computed});

0 comments on commit 3148c4f

Please sign in to comment.