:hammer: Remove all Magic Numbers · FagnerMartinsBrack/jack-the-moneylender@f30fe0e

GitHub 1 min read
View original
Crawl details
  • Current

This article is too short to summarise.

@@ -9,24 +9,27 @@

99
1010

const interestToPayFor = (loanAmount) => {

1111

const END_OF_FIRST_RANGE = Money('$2000.00');

12+

const END_OF_SECOND_RANGE = Money('$5000.00');

13+
1214

const CENTS_FOR_FIRST_RANGE = Money('$0.00');

1315

const CENTS_FOR_SECOND_RANGE = Money('$0.09');

16+

const CENTS_FOR_THIRD_RANGE = Money('$0.14');

1417
1518

if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) {

1619

const dollarsAboveThreshold = loanAmount.minus(END_OF_FIRST_RANGE);

1720

const interestAmount = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThreshold);

1821

return interestAmount;

1922

}

2023
21-

if (loanAmount.greaterThan(Money('$5000.00'))) {

24+

if (loanAmount.greaterThan(END_OF_SECOND_RANGE)) {

2225

let interestAmount = Money('$0.00');

2326
2427

const dollarsAboveThresholdForSecondRange = loanAmount.minus(END_OF_FIRST_RANGE);

2528

const interestAmountForSecondRange = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThresholdForSecondRange);

2629

interestAmount = interestAmount.plus(interestAmountForSecondRange);

2730
28-

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);

3033

interestAmount = interestAmount.plus(interestAmountForThirdRange);

3134
3235

return interestAmount;