Skip to content

Commit

Permalink
Replaced the magic number 22 with a constant named billableDaysPerMon…
Browse files Browse the repository at this point in the history
…th (#2218)
  • Loading branch information
mazzog authored Jul 19, 2023
1 parent b5adfa7 commit 55f2a65
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions exercises/concept/freelancer-rates/.meta/exemplar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ export function daysInBudget(budget, ratePerHour) {
* @returns {number} the discounted rate, rounded up
*/
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
const numMonths = Math.floor(numDays / 22);
const monthlyRate = 22 * dayRate(ratePerHour);
const billableDaysPerMonth = 22;
const numMonths = Math.floor(numDays / billableDaysPerMonth);
const monthlyRate = billableDaysPerMonth * dayRate(ratePerHour);
const monthlyDiscountedRate = (1 - discount) * monthlyRate;

const numExtraDays = numDays % 22;
const numExtraDays = numDays % billableDaysPerMonth;
const priceExtraDays = numExtraDays * dayRate(ratePerHour);

return Math.ceil(numMonths * monthlyDiscountedRate + priceExtraDays);
Expand Down

0 comments on commit 55f2a65

Please sign in to comment.