Hello!
My name is Gabriel Frederico and this is my first time using this forum. I noticed pull requests are currently paused in the JavaScript Track, but I would like to propose an amendment to the exemplar solution.
Currently, the last task (Task 3) has the following code as the exemplar solution:
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
const numMonths = Math.floor(numDays / 22);
const monthlyRate = 22 * dayRate(ratePerHour);
const monthlyDiscountedRate = (1 - discount) * monthlyRate;
const numExtraDays = numDays % 22;
const priceExtraDays = numExtraDays * dayRate(ratePerHour);
return Math.ceil(numMonths * monthlyDiscountedRate + priceExtraDays);
}
Yet, the number 22 is used three times. Based on the DRY principle and the fact that the freelancer might increase or decrease the number of billable days in a month, I believe that value should be passed as a variable. The result would be:
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
const billableDaysPerMonth = 22
const numMonths = Math.floor(numDays / billableDaysPerMonth);
const monthlyRate = billableDaysPerMonth * dayRate(ratePerHour);
const monthlyDiscountedRate = (1 - discount) * monthlyRate;
const numExtraDays = numDays % billableDaysPerMonth;
const priceExtraDays = numExtraDays * dayRate(ratePerHour);
return Math.ceil(numMonths * monthlyDiscountedRate + priceExtraDays);
}
Also, the daily rate is calculated twice, which should be also put in a variable. Making the final code something like this:
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
const billableDaysPerMonth = 22
const fullMonths = Math.floor(numDays / billableDaysPerMonth);
const dailyRate = dayRate(ratePerHour);
const monthlyRate = billableDaysPerMonth * dailyRate;
const monthlyDiscountedRate = (1 - discount) * monthlyRate;
const remainingDays = numDays % billableDaysPerMonth;
const remainingDaysRate = remainingDays * dailyRate;
return Math.ceil((fullMonths * monthlyDiscountedRate) + remainingDaysRate);
}
This is just a suggestion, of course. Thank you for any feedback.