Created
December 2, 2016 01:03
-
-
Save jineeshjohn/a0a105863db08befc365e6b7534fd185 to your computer and use it in GitHub Desktop.
This file contains 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
// Chaining | |
var lyrics=[ | |
{line:1,words:"Im a lumberjack and Im okay"}, | |
{line:2,words:"I sleep all night and I work all day"}, | |
{line:3,words:"Hes a lumberjack and hes okay"}, | |
{line:4,words:"He sleeps all night and he works all day"} | |
]; | |
var values = _(lyrics).chain() | |
.map(function(line) { | |
return line.words.split(); | |
}) | |
.flatten() | |
.reduce(function(counts, word) { | |
counts[word] = (counts[word] || 0) + 1; | |
return counts; | |
}, {}) | |
.value(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment