@@ -7,12 +7,7 @@
|
7 | 7 | assert.strictEqual(actual, expected); |
8 | 8 | } |
9 | 9 | |
10 | | -const calculateInterestForGreaterThan2000 = (loanAmount, endOfRange, interestPerDollar, previousInterestPerDollar) => { |
11 | | -const greaterThan2000 = { |
12 | | -endOfRange: endOfRange, |
13 | | -interestPerDollar: interestPerDollar, |
14 | | -previousInterestPerDollar: previousInterestPerDollar |
15 | | -}; |
| 10 | +const calculateInterestForGreaterThan2000 = (loanAmount, greaterThan2000) => { |
16 | 11 | const dollarsAboveThreshold = loanAmount.minus(greaterThan2000.endOfRange); |
17 | 12 | const interestToPay = greaterThan2000.interestPerDollar.minus(greaterThan2000.previousInterestPerDollar).multipliedBy(dollarsAboveThreshold); |
18 | 13 | return interestToPay; |
|
43 | 38 | if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) { |
44 | 39 | let interestAmount = Money('$0.00'); |
45 | 40 | |
| 41 | +const greaterThan2000 = { |
| 42 | +endOfRange: END_OF_FIRST_RANGE, |
| 43 | +interestPerDollar: CENTS_FOR_SECOND_RANGE, |
| 44 | +previousInterestPerDollar: CENTS_FOR_FIRST_RANGE |
| 45 | +}; |
46 | 46 | interestAmount = interestAmount.plus( |
47 | | -calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE) |
| 47 | +calculateInterestForGreaterThan2000(loanAmount, greaterThan2000) |
48 | 48 | ); |
49 | 49 | |
50 | 50 | return interestAmount; |
@@ -53,8 +53,13 @@
|
53 | 53 | if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) { |
54 | 54 | let interestAmount = Money('$0.00'); |
55 | 55 | |
| 56 | +const greaterThan2000 = { |
| 57 | +endOfRange: END_OF_FIRST_RANGE, |
| 58 | +interestPerDollar: CENTS_FOR_SECOND_RANGE, |
| 59 | +previousInterestPerDollar: CENTS_FOR_FIRST_RANGE |
| 60 | +}; |
56 | 61 | interestAmount = interestAmount.plus( |
57 | | -calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE) |
| 62 | +calculateInterestForGreaterThan2000(loanAmount, greaterThan2000) |
58 | 63 | ); |
59 | 64 | interestAmount = interestAmount.plus( |
60 | 65 | calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE) |
@@ -66,8 +71,13 @@
|
66 | 71 | if (loanAmount.greaterThan(END_OF_THIRD_RANGE)) { |
67 | 72 | let interestAmount = Money('$0.00'); |
68 | 73 | |
| 74 | +const greaterThan2000 = { |
| 75 | +endOfRange: END_OF_FIRST_RANGE, |
| 76 | +interestPerDollar: CENTS_FOR_SECOND_RANGE, |
| 77 | +previousInterestPerDollar: CENTS_FOR_FIRST_RANGE |
| 78 | +}; |
69 | 79 | interestAmount = interestAmount.plus( |
70 | | -calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE) |
| 80 | +calculateInterestForGreaterThan2000(loanAmount, greaterThan2000) |
71 | 81 | ); |
72 | 82 | interestAmount = interestAmount.plus( |
73 | 83 | calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE) |
|