Skip to content

Instantly share code, notes, and snippets.

@daryl-sf
Created October 25, 2023 14:06
Show Gist options
  • Save daryl-sf/923881cf9be8cfd8751e4cb0065a9471 to your computer and use it in GitHub Desktop.
Save daryl-sf/923881cf9be8cfd8751e4cb0065a9471 to your computer and use it in GitHub Desktop.
Quick and Dirty interest calc
const interestCalc = (init, rate, years) => {
const pot = [...Array(years).keys()].reduce((acc, c) => {
const earnings = acc * rate;
acc += earnings;
console.log(`Earnings: £${earnings.toFixed(2)}, New Total: £${acc.toFixed(2)}`);
return acc;
}, init);
console.log(`Total: £${pot.toFixed(2)}. Total Earned: £${(pot - init).toFixed(2)}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment