-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 2- DepositProfit.js
58 lines (41 loc) · 1.43 KB
/
Day 2- DepositProfit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*Deposit Profit
https://scrimba.com/scrim/coab9473f84df5ee10899e99d
DESCRIPTION:
You have deposited a specific amount of dollars into your ban account.
Each year your balance increases at the same growth rate.
Found out how long it would take for yout balance to pass a specific threshold with the assumption that you don't make any additional deposits.
Example:
For deposit = 100, rate = 20, and threshold = 170, the output should be the depositProfit(deposit, rate, threshold) = 3.
Each year the amount of money on your account increases by 20%. It means that throughout the years your balance would be:
year 0: 100;
year 1: 120;
year 2: 144;
year 2: 172,8
Thus, it will take 3 years for your balance to pass the threshold, which is the answer.
*/
const depositProfit = (deposit, rate, threshold) => {
let money = deposit
let year = 0
while (money < threshold) {
money = (money+(money/100)*rate)
year++
}
return year
}
/**
* 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);
});
});