This file contains 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
assert.strictEqual(actual, expected); | |
} | |
- const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange, centsForFirstRange) => { | |
- const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange); | |
- const interestForGreaterThan2000 = centsForSecondRange.minus(centsForFirstRange).multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
- return interestForGreaterThan2000; | |
+ const calculateInterestForGreaterThan2000 = (loanAmount, endOfRange, interestPerDollar, previousInterestPerDollar) => { | |
+ const dollarsAboveThreshold = loanAmount.minus(endOfRange); | |
+ const interestToPay = interestPerDollar.minus(previousInterestPerDollar).multipliedBy(dollarsAboveThreshold); |
This file contains 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
@@ -7,9 +7,9 @@ | |
assert.strictEqual(actual, expected); | |
} | |
- const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange) => { | |
+ const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange, centsForFirstRange) => { | |
const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange); | |
- const interestForGreaterThan2000 = centsForSecondRange.multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
+ const interestForGreaterThan2000 = centsForSecondRange.minus(centsForFirstRange).multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
return interestForGreaterThan2000; |
This file contains 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
const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange) => { | |
const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange); | |
const interestForGreaterThan2000 = centsForSecondRange.multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
return interestForGreaterThan2000; | |
}; | |
const calculateInterestForGreaterThan5000 = (loanAmount, endOfSecondRange, centsForThirdRange, centsForSecondRange) => { | |
const dollarsAboveThresholdForGreaterThan5000 = loanAmount.minus(endOfSecondRange); | |
const interestForGreaterThan5000 = centsForThirdRange.minus(centsForSecondRange).multipliedBy(dollarsAboveThresholdForGreaterThan5000); | |
return interestForGreaterThan5000; | |
}; |
This file contains 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
if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) { | |
let interestAmount = Money('$0.00'); | |
interestAmount = interestAmount.plus( | |
calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE) | |
); | |
return interestAmount; | |
} | |
if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) { | |
let interestAmount = Money('$0.00'); | |
interestAmount = interestAmount.plus( |
This file contains 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
@@ -7,6 +7,12 @@ | |
assert.strictEqual(actual, expected); | |
} | |
+ const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange) => { | |
+ const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange); | |
+ const interestForGreaterThan2000 = centsForSecondRange.multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
+ return interestForGreaterThan2000; | |
+ }; | |
+ |
This file contains 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
const CENTS_FOR_FOURTH_RANGE = Money('$0.21'); | |
if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) { | |
- const dollarsAboveThreshold = loanAmount.minus(END_OF_FIRST_RANGE); | |
- const interestAmount = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThreshold); | |
+ const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange) => { | |
+ const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange); | |
+ const interestForGreaterThan2000 = centsForSecondRange.multipliedBy(dollarsAboveThresholdForGreaterThan2000); | |
+ return interestForGreaterThan2000; | |
+ }; |
This file contains 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
const interestToPayFor = (loanAmount) => { | |
const END_OF_FIRST_RANGE = Money('$2000.00'); | |
const END_OF_SECOND_RANGE = Money('$5000.00'); | |
const END_OF_THIRD_RANGE = Money('$10000.00'); | |
const CENTS_FOR_FIRST_RANGE = Money('$0.00'); | |
const CENTS_FOR_SECOND_RANGE = Money('$0.09'); | |
const CENTS_FOR_THIRD_RANGE = Money('$0.14'); | |
const CENTS_FOR_FOURTH_RANGE = Money('$0.21'); | |
if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) { | |
const dollarsAboveThreshold = loanAmount.minus(END_OF_FIRST_RANGE); |
This file contains 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
if (loanAmount.equalsTo(Money('$10001.00'))) { | |
let interestAmount = Money('$0.00'); | |
+ const dollarsAboveThresholdForSecondRange = loanAmount.minus(END_OF_FIRST_RANGE); | |
+ const interestAmountForSecondRange = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThresholdForSecondRange); | |
+ interestAmount = interestAmount.plus(interestAmountForSecondRange); | |
+ | |
const dollarsAboveThresholdForThirdRange = loanAmount.minus(END_OF_SECOND_RANGE); | |
const interestAmountForThirdRange = CENTS_FOR_THIRD_RANGE.minus(CENTS_FOR_SECOND_RANGE).multipliedBy(dollarsAboveThresholdForThirdRange); | |
interestAmount = interestAmount.plus(interestAmountForThirdRange); |
This file contains 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
if (loanAmount.equalsTo(Money('$10001.00'))) { | |
let interestAmount = Money('$0.00'); | |
+ const dollarsAboveThresholdForThirdRange = loanAmount.minus(END_OF_SECOND_RANGE); | |
+ const interestAmountForThirdRange = CENTS_FOR_THIRD_RANGE.minus(CENTS_FOR_SECOND_RANGE).multipliedBy(dollarsAboveThresholdForThirdRange); | |
+ interestAmount = interestAmount.plus(interestAmountForThirdRange); | |
+ | |
const dollarsAboveThresholdForFourthRange = Money('$10001.00').minus(Money('$10000.00')); | |
const interestAmountForFourthRange = Money('$0.21').minus(Money('$0.14')).multipliedBy(dollarsAboveThresholdForFourthRange); | |
interestAmount = interestAmount.plus(interestAmountForFourthRange); |
This file contains 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
@@ -21,7 +21,7 @@ | |
return interestAmount; | |
} | |
- if (loanAmount.greaterThan(END_OF_SECOND_RANGE)) { | |
+ if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) { | |
let interestAmount = Money('$0.00'); | |
const dollarsAboveThresholdForSecondRange = loanAmount.minus(END_OF_FIRST_RANGE); | |
@@ -35,6 +35,16 @@ |