Skip to content

Instantly share code, notes, and snippets.

@xseignard
Last active August 29, 2015 14:14
Show Gist options
  • Save xseignard/1c6a0c1f1eb976e39da8 to your computer and use it in GitHub Desktop.
Save xseignard/1c6a0c1f1eb976e39da8 to your computer and use it in GitHub Desktop.
cadeau!
var data = {
_id: "fridge",
values: [
{
hourAgo: 0,
value: 10
},
{
hourAgo: 2,
value: 12
},
{
hourAgo: 1,
value: 11
},
{
hourAgo: 22,
value: 22
},
{
hourAgo: 10,
value: 11
}
]
};
var computeStats = function(data, ago, max) {
// create a 0 filled array
var computedData = Array.apply(null, new Array(max)).map(Number.prototype.valueOf, 0);
// plae each values at the right place
data.values.forEach(function(current) {
computedData.splice(current[ago], 1, current.value);
});
console.log(computedData);
};
computeStats(data, 'hourAgo', 24);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment