mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
0.4.1 is out, with array methods proxied for wrapped objects, an _.breakLoop(), and an _.isEmpty()
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
$(document).ready(function() {
|
||||
|
||||
|
||||
module("Underscore chaining.");
|
||||
|
||||
|
||||
test("chaining: map/flatten/reduce", function() {
|
||||
var lyrics = [
|
||||
"I'm a lumberjack and I'm okay",
|
||||
@@ -12,14 +12,14 @@ $(document).ready(function() {
|
||||
var counts = _(lyrics).chain()
|
||||
.map(function(line) { return line.split(''); })
|
||||
.flatten()
|
||||
.reduce({}, function(hash, l) {
|
||||
.reduce({}, function(hash, l) {
|
||||
hash[l] = hash[l] || 0;
|
||||
hash[l]++;
|
||||
return hash;
|
||||
}).get();
|
||||
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
|
||||
});
|
||||
|
||||
|
||||
test("chaining: select/reject/sortBy", function() {
|
||||
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
||||
numbers = _(numbers).chain().select(function(n) {
|
||||
@@ -31,5 +31,17 @@ $(document).ready(function() {
|
||||
}).get();
|
||||
equals(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
|
||||
});
|
||||
|
||||
|
||||
test("chaining: reverse/concat/unshift/pop/map", function() {
|
||||
var numbers = [1,2,3,4,5];
|
||||
numbers = _(numbers).chain()
|
||||
.reverse()
|
||||
.concat([5, 5, 5])
|
||||
.unshift(17)
|
||||
.pop()
|
||||
.map(function(n){ return n * 2; })
|
||||
.get();
|
||||
equals(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user