Skip to content

Instantly share code, notes, and snippets.

@puttputt
Created March 19, 2014 01:39
Show Gist options
  • Save puttputt/9633902 to your computer and use it in GitHub Desktop.
Save puttputt/9633902 to your computer and use it in GitHub Desktop.
reduce = function(key, values) {
var prices = 0.0;
var volume = 0.0;
var total = 0.0;
var high = values[0].price;
var low = values[0].price;
var count = 0;
values.forEach(function(value)
{
prices += value.price;
volume+= value.volume;
total+= value.total;
if(value.price > high)
high = value.price;
if(value.price < low)
low = value.price;
count+=1;
});
var result = {
open: values[0].price,
close: values[values.length-1].price,
high: high,
low: low,
price: prices/count,
volume: volume,
total: total,
count: count,
};
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment