Skip to content

Instantly share code, notes, and snippets.

@montyanderson
Created July 16, 2015 12:22
Show Gist options
  • Save montyanderson/09dd6e53b32a399c573d to your computer and use it in GitHub Desktop.
Save montyanderson/09dd6e53b32a399c573d to your computer and use it in GitHub Desktop.
Convert a ratio to an array of percentages.
function rtp(ratios) {
var total = 0;
ratios.forEach(function(ratio) {
total += ratio;
});
var percentages = [];
ratios.forEach(function(ratio) {
var percentage = (ratio / total) * 100;
percentages.push(percentage);
});
return percentages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment