[ Launch: Tributary inlet ] 6515650 by roundrobin
-
-
Save roundrobin/6515650 to your computer and use it in GitHub Desktop.
Percentage growth
This file contains 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
{"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"} |
This file contains 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 = [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