Skip to content

Commit

Permalink
remove constant variables from function
Browse files Browse the repository at this point in the history
  • Loading branch information
TargoniyAnatoliy committed Oct 31, 2024
1 parent 3d9d0b3 commit 7891826
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
* @return {number}
*/

const DAY_RENT = 40;
const LONG_TERM = 7;
const SHORT_TERM = 3;
const LONG_TERM_DISCOUNT = -50;
const SHORT_TERM_DISCOUNT = -20;

function calculateRentalCost(days) {
const DAY_RENT = 40;
const SHORT_TERM_DISCOUNT = -20;
const LONG_TERM_DISCOUNT = -50;
const TOTAL_RENT = DAY_RENT * days;

if (days >= 3 && days < 7) {
return DAY_RENT * days + SHORT_TERM_DISCOUNT;
if (days >= SHORT_TERM && days < LONG_TERM) {
return TOTAL_RENT + SHORT_TERM_DISCOUNT;
}

if (days >= 7) {
return DAY_RENT * days + LONG_TERM_DISCOUNT;
if (days >= LONG_TERM) {
return TOTAL_RENT + LONG_TERM_DISCOUNT;
}

return DAY_RENT * days;
return TOTAL_RENT;
}

module.exports = calculateRentalCost;

0 comments on commit 7891826

Please sign in to comment.