Created
January 29, 2011 17:25
-
-
Save victusfate/802013 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var lyrics = [ | |
| {line : 1, words : "I'm a lumberjack and I'm okay"}, | |
| {line : 2, words : "I sleep all night and I work all day"}, | |
| {line : 3, words : "He's a lumberjack and he's okay"}, | |
| {line : 4, words : "He sleeps all night and he works all day"} | |
| ]; | |
| _(lyrics).chain() | |
| .map(function(line) { return line.words.split(' '); }) | |
| .flatten() | |
| .reduce(function(counts, word) { | |
| counts[word] = (counts[word] || 0) + 1; | |
| return counts; | |
| }, {}).value(); | |
| => {lumberjack : 2, all : 4, night : 2 ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment