Skip to content

Instantly share code, notes, and snippets.

@apipkin
Created June 29, 2011 15:04
Show Gist options
  • Save apipkin/1054019 to your computer and use it in GitHub Desktop.
Save apipkin/1054019 to your computer and use it in GitHub Desktop.
function (key, values, rereduce) {
// value -> [count, min, max, mean]
var i = 0
, l = values.length
, min = values[i][2] // set min to the first max
, max = 0
, mean = 0
, count = 0
;
for (; i < l; i++) {
count = count + values[i][0];
min = Math.min(min, values[i][1]);
max = Math.max(max, values[i][2]);
mean = ((mean * count) + (values[i][3] * values[i][0])) / (count);
}
return [count, min, max, mean];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment