Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Created April 11, 2015 14:58
Show Gist options
  • Select an option

  • Save IPRIT/2a2018bf4c2881db00ed to your computer and use it in GitHub Desktop.

Select an option

Save IPRIT/2a2018bf4c2881db00ed to your computer and use it in GitHub Desktop.
Reduce example
var util = require('util');
function countWords(inputWords) {
return inputWords.reduce(function (prev, cur) {
prev[cur] = ++prev[cur] || 1;
return prev;
}, {});
}
module.exports = countWords;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment