mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Fixes #403
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user