Skip to content

Instantly share code, notes, and snippets.

@skyler
Created December 9, 2011 18:57
Show Gist options
  • Save skyler/1452807 to your computer and use it in GitHub Desktop.
Save skyler/1452807 to your computer and use it in GitHub Desktop.
var map = function() {
for (var i in this.v) {
var yes = (this.v[i].v > 0) ? 1 : 0;
var no = (this.v[i].v < 0) ? 1 : 0;
var key = {themeID: this.v[i].t}
var value = { yes: yes, no: no };
emit(key, value);
}
}
var reduce = function(key, values) {
var votes_list = {yes: 0, no: 0}
for (var i in values) {
votes_list.yes += values[i].yes;
votes_list.no += values[i].no;
}
return votes_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment