function depositProfit(deposit, rate, threshold) {
//formula for calculation: deposit(1 + (rate / 100)^years)
let years
let amount = 0
const interestRate = (1 + (rate / 100))
for (years = 1; amount <= threshold; years++) {
amount = deposit * Math.pow(interestRate, years)
}
return years - 1
}
/**
* Test Suite
*/
describe('depositProfit()', () => {
it('returns number of years it will take to hit threshold based off of deposit & rate', () => {
// arrange
const deposit = 100;
const rate = 20;
const threshold = 170;
// act
const result = depositProfit(deposit, rate, threshold)
// log
console.log("result: ", result);
// assert
expect(result).toBe(3);
});
});