Created
May 1, 2018 17:03
-
-
Save mwakipesile/ee468f255c873a4c3980241944aacb47 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
function wordCount(str) { | |
var words = str.toLowerCase().split(/\W*\s\W*|[^'\w]+/); | |
var incrementWordCount = (word_count, word) => { | |
word_count[word] = 1 + (word_count[word] | 0) | |
return word_count; | |
}; | |
return words.reduce(incrementWordCount, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment