Last active
August 29, 2015 14:14
-
-
Save xseignard/1c6a0c1f1eb976e39da8 to your computer and use it in GitHub Desktop.
cadeau!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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