Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created September 10, 2013 21:03
Show Gist options
  • Save roundrobin/6515650 to your computer and use it in GitHub Desktop.
Save roundrobin/6515650 to your computer and use it in GitHub Desktop.
Percentage growth
{"description":"Percentage growth","endpoint":"","display":"svg","public":true,"require":[{"name":"underscore","url":"http://underscorejs.org/underscore-min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/50AePSy.png"}
var data = [1,2,4,0,5,6];
console.log(data);
var pG = [];
_.each(data, function(item, i){
if(i > 0){
var growth = (data[i] - data[i-1]) / Math.abs(data[i-1]);
if(growth == Infinity) growth = 1;
pG.push(growth*100);
}
});
var sum = _.reduce(pG, function(memo, num){ return memo + num; }, 0);
console.log(pG,sum/pG.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment