Instantly share code, notes, and snippets.

Embed
What would you like to do?
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