Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordCount - Functional
var paragraph = 'How much wood would a woodchuck chuck\nIf a woodchuck could chuck wood?\nHe would chuck, he would, as much as he could,\nAnd chuck as much as a woodchuck would\nIf a woodchuck could chuck wood.';
var paraCount = paragraph.split('\n')
.replace(/[^\w\s]/g, '')
.reduce(wordCount, {});
function joinArray(last, now) {
return last.toLowerCase().concat(' ' + now.toLowerCase());
function wordCount(map, word) {
map[word] = (map[word] || 0) + 1;
return map;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.