version 0.4.2 -- quick patch to rename get() to value() for clarity, and adding jQuery comparisons in the speed tests

This commit is contained in:
Jeremy Ashkenas
2009-11-09 08:28:32 -05:00
parent 7127d404d2
commit f6e67a5bf2
5 changed files with 43 additions and 28 deletions

View File

@@ -16,7 +16,7 @@ $(document).ready(function() {
hash[l] = hash[l] || 0;
hash[l]++;
return hash;
}).get();
}).value();
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
});
@@ -28,7 +28,7 @@ $(document).ready(function() {
return n % 4 == 0;
}).sortBy(function(n) {
return -n;
}).get();
}).value();
equals(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
});
@@ -40,7 +40,7 @@ $(document).ready(function() {
.unshift(17)
.pop()
.map(function(n){ return n * 2; })
.get();
.value();
equals(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
});

View File

@@ -1,54 +1,64 @@
(function() {
var numbers = [];
for (var i=0; i<1000; i++) numbers.push(i);
var objects = _.map(numbers, function(n){ return {num : n}; });
var randomized = _.sortBy(numbers, function(){ return Math.random(); });
JSLitmus.test('_.each()', function() {
var timesTwo = [];
_.each(numbers, function(num){ timesTwo.push(num * 2); });
return timesTwo;
});
JSLitmus.test('_(list).each()', function() {
var timesTwo = [];
_(numbers).each(function(num){ timesTwo.push(num * 2); });
return timesTwo;
});
JSLitmus.test('jQuery.each()', function() {
var timesTwo = [];
jQuery.each(numbers, function(){ timesTwo.push(this * 2); });
return timesTwo;
});
JSLitmus.test('_.map()', function() {
return _.map(objects, function(obj){ return obj.num; });
});
JSLitmus.test('jQuery.map()', function() {
return jQuery.map(objects, function(obj){ return obj.num; });
});
JSLitmus.test('_.pluck()', function() {
return _.pluck(objects, 'num');
});
JSLitmus.test('_.uniq()', function() {
return _.uniq(randomized);
});
JSLitmus.test('_.uniq() (sorted)', function() {
return _.uniq(numbers, true);
});
JSLitmus.test('_.sortBy()', function() {
return _.sortBy(numbers, function(num){ return -num; });
});
JSLitmus.test('_.isEqual()', function() {
return _.isEqual(numbers, randomized);
});
JSLitmus.test('_.keys()', function() {
return _.keys(objects);
});
JSLitmus.test('_.values()', function() {
return _.values(objects);
});
JSLitmus.test('_.intersect()', function() {
return _.intersect(numbers, randomized);
});