Skip to content

Instantly share code, notes, and snippets.

@jearle
Created November 28, 2017 18:05
Show Gist options
  • Save jearle/2eccfc7546e75d7c099aa44bafe7223c to your computer and use it in GitHub Desktop.
Save jearle/2eccfc7546e75d7c099aa44bafe7223c to your computer and use it in GitHub Desktop.
const calculateInterest = ({
initialAmount = 0,
additionalPerYear = 0,
interestRate = 0,
years = 0,
} = {}) => {
const annuityDue = interestRate / (interestRate + 1)
const x = (initialAmount + (additionalPerYear / annuityDue))
const y = Math.pow(1 + interestRate, years)
const z = additionalPerYear / annuityDue
return ((x * y) - z)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment