Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
Created August 17, 2011 17:18
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 simenbrekken/1152060 to your computer and use it in GitHub Desktop.
Save simenbrekken/1152060 to your computer and use it in GitHub Desktop.
var map = function() {
var completions = this.statistics.completions.total;
emit(key, {
created: {
count: 1,
length: this.length
},
completed: {
count: completions,
length: this.length * completions
}
});
};
var reduce = function(key, values) {
var result = {
created: {
count: 0,
length: 0
},
completed: {
count: 0,
length: 0
}
};
for (var i = 0, l = values.length; i < l; ++i) {
var value = values[i];
result.created.count += value.created.count;
result.created.length += value.created.length;
result.completed.count += value.completed.count;
result.completed.length += value.completed.length;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment