-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,23 @@ | |
* | ||
* @return {number} | ||
*/ | ||
|
||
const LONG_TERM = 7; | ||
const LONG_TERM_DISCOUNT = 50; | ||
const SHORT_TERM = 3; | ||
const SHORT_TERM_DISCOUNT = 20; | ||
const RENT = 40; | ||
|
||
function calculateRentalCost(days) { | ||
// write code here | ||
if (days >= LONG_TERM) { | ||
return RENT * days - LONG_TERM_DISCOUNT; | ||
} | ||
|
||
if (days >= SHORT_TERM) { | ||
return RENT * days - SHORT_TERM_DISCOUNT; | ||
Comment on lines
+18
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
module.exports = calculateRentalCost; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe 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. |
||
}); |
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.