Created
June 26, 2013 21:37
-
-
Save benguillet/5871953 to your computer and use it in GitHub Desktop.
Word count in Javascript with WebMapReduce (http://webmapreduce.sourceforge.net/).
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
// Javascript Mapper | |
function mapper(key, value) { | |
var words = key.split(' '); | |
for (var i = 0; i < words.length; ++i) { | |
Wmr.emit(words[i], '1'); | |
} | |
} |
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
// 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