:hammer: Remove all Magic Numbers · FagnerMartinsBrack/jack-the-moneylender@f30fe0e
View original- current
This article is too short to summarise.
@@ -9,24 +9,27 @@
991010const interestToPayFor = (loanAmount) => {
1111const END_OF_FIRST_RANGE = Money('$2000.00');
12+const END_OF_SECOND_RANGE = Money('$5000.00');
13+1214const CENTS_FOR_FIRST_RANGE = Money('$0.00');
1315const CENTS_FOR_SECOND_RANGE = Money('$0.09');
16+const CENTS_FOR_THIRD_RANGE = Money('$0.14');
14171518if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) {
1619const dollarsAboveThreshold = loanAmount.minus(END_OF_FIRST_RANGE);
1720const interestAmount = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThreshold);
1821return interestAmount;
1922}
202321-if (loanAmount.greaterThan(Money('$5000.00'))) {
24+if (loanAmount.greaterThan(END_OF_SECOND_RANGE)) {
2225let interestAmount = Money('$0.00');
23262427const dollarsAboveThresholdForSecondRange = loanAmount.minus(END_OF_FIRST_RANGE);
2528const interestAmountForSecondRange = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThresholdForSecondRange);
2629interestAmount = interestAmount.plus(interestAmountForSecondRange);
273028-const dollarsAboveThresholdForThirdRange = loanAmount.minus(Money('$5000.00'));
29-const interestAmountForThirdRange = Money('$0.14').minus(Money('$0.09')).multipliedBy(dollarsAboveThresholdForThirdRange);
31+const dollarsAboveThresholdForThirdRange = loanAmount.minus(END_OF_SECOND_RANGE);
32+const interestAmountForThirdRange = CENTS_FOR_THIRD_RANGE.minus(CENTS_FOR_SECOND_RANGE).multipliedBy(dollarsAboveThresholdForThirdRange);
3033interestAmount = interestAmount.plus(interestAmountForThirdRange);
31343235return interestAmount;