Created
April 11, 2015 14:57
-
-
Save IPRIT/92d566c1e5772a8ae15f 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 util = require('util'); | |
| function countWords(inputWords) { | |
| return inputWords.reduce(function (prev, cur) { | |
| if (!util.isObject(prev)) { | |
| var obj = {}; | |
| obj[prev] = 1; | |
| obj[cur] = 1; | |
| return obj; | |
| } | |
| if (!prev[cur]) { | |
| prev[cur] = 0; | |
| } | |
| ++prev[cur]; | |
| return prev; | |
| }); | |
| } | |
| module.exports = countWords; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment