Skip to content

Instantly share code, notes, and snippets.

@HoraceShmorace
Last active March 28, 2019 22:07
Show Gist options
  • Save HoraceShmorace/5b3ade7e5f90c79df0d7190500dc3cca to your computer and use it in GitHub Desktop.
Save HoraceShmorace/5b3ade7e5f90c79df0d7190500dc3cca to your computer and use it in GitHub Desktop.
Calculate simple earnings with compounded interest (margins)
const MAX_PERIODS = 52
const MARGIN_PER_PERIOD = 0.05
function calc(v, t) {
console.log(v)
if (t === 0) return v;
const n = (v * MARGIN_PER_PERIOD) + v
return calc(n, --t)
}
calc(5000, MAX_PERIODS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment