Skip to content

Instantly share code, notes, and snippets.

@clemgrim
Last active September 16, 2017 19:44
Show Gist options
  • Save clemgrim/3d7f3e64ab51bdb04c3430d001c8bea3 to your computer and use it in GitHub Desktop.
Save clemgrim/3d7f3e64ab51bdb04c3430d001c8bea3 to your computer and use it in GitHub Desktop.
const steps = [
{start: 60000, percent: .45},
{start: 34000, percent: .37},
{start: 20200, percent: .3},
{start: 12450, percent: .24},
{start: 0, percent: .19}
];
function calc(x) {
for (let step of steps) {
if (step.start < x) {
return (x - step.start) * (1 - step.percent) + calc(step.start);
}
}
return x;
}
function getPercent(x) {
return 100 * (1 - calc(x) / x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment