Problem
We have an amount of money amt > 0 and we deposit it with an interest rate of p percent divided by 360 per day on the 1st of January 2021. We want to have an amount total >= a0.
Our function should take these three parameters and return the date at which the amount will be equal to the desired amount
Example
Following is the code −
const principal = 100; const amount = 150; const interest = 2; const findDate = (principal, amount, interest) => { const startingDate = new Date('2021-01-01') const dailyInterestRate = interest / 36000 let startingMoney = principal let daysPassed = 0 while (startingMoney < amount) { daysPassed++ startingMoney += startingMoney * dailyInterestRate }; startingDate.setDate(startingDate.getDate() + daysPassed) return startingDate.toISOString().split('T')[0] }; console.log(findDate(principal, amount, interest));
Output
2040-12-26