This commit is contained in:
Jeremy Ashkenas
2011-12-16 12:41:20 -05:00
parent eb42c856c4
commit 3c5686f784
3 changed files with 9 additions and 6 deletions

View File

@@ -49,6 +49,9 @@ $(document).ready(function() {
var ifnull = _.map(null, function(){});
ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly');
var length = _.map(Array(2), function(v) { return v; }).length;
equals(length, 2, "can preserve a sparse array's length");
});
test('collections: reduce', function() {
@@ -83,7 +86,7 @@ $(document).ready(function() {
var sparseArray = [];
sparseArray[0] = 20;
sparseArray[2] = -5;
equals(_.reduce(sparseArray, function(a, b){ return a - b }), 25, 'initially-sparse arrays with no memo');
equals(_.reduce(sparseArray, function(a, b){ return a - b; }), 25, 'initially-sparse arrays with no memo');
});
test('collections: reduceRight', function() {
@@ -112,7 +115,7 @@ $(document).ready(function() {
var sparseArray = [];
sparseArray[0] = 20;
sparseArray[2] = -5;
equals(_.reduceRight(sparseArray, function(a, b){ return a - b }), -25, 'initially-sparse arrays with no memo');
equals(_.reduceRight(sparseArray, function(a, b){ return a - b; }), -25, 'initially-sparse arrays with no memo');
});
test('collections: detect', function() {

View File

@@ -112,10 +112,9 @@ $(document).ready(function() {
throttledUpdate(1); throttledUpdate(2); throttledUpdate(3);
setTimeout(function(){ throttledUpdate(4); }, 120);
setTimeout(function(){ throttledUpdate(5); }, 140);
setTimeout(function(){ throttledUpdate(6); }, 260);
setTimeout(function(){ throttledUpdate(7); }, 270);
_.delay(function(){ ok(value == 1, "updated to latest value"); }, 40);
_.delay(function(){ ok(value == 7, "updated to latest value"); start(); }, 400);
setTimeout(function(){ throttledUpdate(6); }, 250);
_.delay(function(){ equals(value, 1, "updated to latest value"); }, 40);
_.delay(function(){ equals(value, 6, "updated to latest value"); start(); }, 400);
});
asyncTest("functions: throttle once", 1, function() {

View File

@@ -102,6 +102,7 @@
each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list);
});
if (obj.length === +obj.length) results.length = obj.length;
return results;
};