re-adding 649f62

This commit is contained in:
Jeremy Ashkenas
2011-12-07 09:35:07 -05:00
parent cf1d69227b
commit 770f0876b3
2 changed files with 21 additions and 11 deletions

View File

@@ -77,13 +77,13 @@ $(document).ready(function() {
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equals(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
// Sparse arrays:
var sparseArray = [];
sparseArray[100] = 10;
sparseArray[200] = 20;
equals(_.reduce(sparseArray, function(a, b){ return a + b }), 30, 'initially-sparse arrays with no memo');
var sparseArray = [];
sparseArray[0] = 20;
sparseArray[2] = -5;
equals(_.reduce(sparseArray, function(a, b){ return a - b }), 25, 'initially-sparse arrays with no memo');
});
test('collections: reduceRight', function() {
@@ -105,6 +105,14 @@ $(document).ready(function() {
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
ok(_.reduceRight(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equals(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
var sparseArray = [];
sparseArray[0] = 20;
sparseArray[2] = -5;
equals(_.reduceRight(sparseArray, function(a, b){ return a - b }), -25, 'initially-sparse arrays with no memo');
});
test('collections: detect', function() {