Last active
April 13, 2020 04:18
-
-
Save lh0x00/22ec40bd5da048f6c966ecaca1c9d8b3 to your computer and use it in GitHub Desktop.
Calculate savings interest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSavingsInterest( | |
numberOfMonths = 12, | |
assetsFirst = 50000000, | |
amountEachMonth = 15000000, | |
percentageOfInterest = 5.35, | |
skipFirstMonth = true, | |
) { | |
const startAt = skipFirstMonth ? 1 : 0; | |
let total = 0; | |
for (let i = startAt; i <= numberOfMonths; i++) { | |
total = i === startAt ? assetsFirst : total + amountEachMonth; | |
let interest = (total * percentageOfInterest) / 100 / 12; | |
total += interest; | |
} | |
return Math.round(total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example: