initial draft of removing sparse array workarounds. · jashkenas/underscore@4e4bc19

1 min read Original article ↗

@@ -52,9 +52,6 @@ $(document).ready(function() {

52525353

var ifnull = _.map(null, function(){});

5454

ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly');

55-56-

var length = _.map(Array(2), function(v) { return v; }).length;

57-

equal(length, 2, "can preserve a sparse array's length");

5855

});

59566057

test('collections: reduce', function() {

@@ -85,11 +82,6 @@ $(document).ready(function() {

8582

ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');

8683

equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');

8784

raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');

88-89-

var sparseArray = [];

90-

sparseArray[0] = 20;

91-

sparseArray[2] = -5;

92-

equal(_.reduce(sparseArray, function(a, b){ return a - b; }), 25, 'initially-sparse arrays with no memo');

9385

});

94869587

test('collections: reduceRight', function() {

@@ -114,11 +106,6 @@ $(document).ready(function() {

114106115107

equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case');

116108

raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');

117-118-

var sparseArray = [];

119-

sparseArray[0] = 20;

120-

sparseArray[2] = -5;

121-

equal(_.reduceRight(sparseArray, function(a, b){ return a - b; }), -25, 'initially-sparse arrays with no memo');

122109

});

123110124111

test('collections: detect', function() {