Skip to content

Instantly share code, notes, and snippets.

@benguillet
Created June 26, 2013 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benguillet/5871953 to your computer and use it in GitHub Desktop.
Save benguillet/5871953 to your computer and use it in GitHub Desktop.
Word count in Javascript with WebMapReduce (http://webmapreduce.sourceforge.net/).
// Javascript Mapper
function mapper(key, value) {
var words = key.split(' ');
for (var i = 0; i < words.length; ++i) {
Wmr.emit(words[i], '1');
}
}
// Javascript Reducer
function reducer(key, values) {
var count = 0;
for (var i = 0; i < values.length; ++i) {
count += parseInt(values[i], 10);
}
Wmr.emit(key, count.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment