From 789182684379beaf3233b9763bc70e721163a909 Mon Sep 17 00:00:00 2001 From: TargoniyAnatoliy Date: Thu, 31 Oct 2024 23:36:07 +0200 Subject: [PATCH] remove constant variables from function --- src/calculateRentalCost.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 1d9f44191..0cb35147d 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -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;