-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solved #5110
base: master
Are you sure you want to change the base?
solved #5110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your implementation of the calculateRentalCost
function is well-structured and meets the task requirements effectively! 🎉 The logic for applying discounts is correct, and the use of constants enhances readability. While the test cases are comprehensive, consider adding comments to clarify the logic and conditions for discounts to improve code readability. Keep up the great work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if (days >= LONG_TERM) { | ||
return RENT * days - LONG_TERM_DISCOUNT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for applying the long-term discount is correct. However, consider adding comments to explain the logic for better readability.
if (days >= SHORT_TERM) { | ||
return RENT * days - SHORT_TERM_DISCOUNT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for applying the short-term discount is correct. Adding comments to explain the conditions and calculations could improve code readability.
return RENT * days - SHORT_TERM_DISCOUNT; | ||
} | ||
|
||
return RENT * days; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return statement for rentals less than the short-term threshold is correct. Consider adding a comment to clarify that this is the default case with no discounts applied.
@@ -3,21 +3,17 @@ | |||
const calculateRentalCost = require('./calculateRentalCost'); | |||
|
|||
test(`Do not add any discount for less than 3 days`, () => { | |||
expect(calculateRentalCost(2)) | |||
.toBe(80); | |||
expect(calculateRentalCost(2)).toBe(80); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value for 2 days of rental should be 80, which is correct given the rental rate of 40 per day with no discount.
}); | ||
|
||
test('Should add the basic discount from 3 to 6 days of rent', () => { | ||
expect(calculateRentalCost(3)) | ||
.toBe(100); | ||
expect(calculateRentalCost(3)).toBe(100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value for 3 days of rental should be 100, which is correct as it includes the short-term discount of 20.
}); | ||
|
||
test('Should add the basic discount from 3 to 6 days of rent', () => { | ||
expect(calculateRentalCost(6)) | ||
.toBe(220); | ||
expect(calculateRentalCost(6)).toBe(220); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value for 6 days of rental should be 220, which is correct as it includes the short-term discount of 20.
}); | ||
|
||
test('Should add an additional discount for 7 and more days of rent', () => { | ||
expect(calculateRentalCost(7)) | ||
.toBe(230); | ||
expect(calculateRentalCost(7)).toBe(230); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value for 7 days of rental should be 230, which is correct as it includes the long-term discount of 50.
No description provided.