This repository was archived by the owner on Jan 14, 2024. It is now read-only.
London 10-Mahendra Balal-javascript core 1-coursework-week2#445
Open
mabalal wants to merge 2 commits intoCodeYourFuture:mainfrom
Open
London 10-Mahendra Balal-javascript core 1-coursework-week2#445mabalal wants to merge 2 commits intoCodeYourFuture:mainfrom
mabalal wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
berkeli
reviewed
Mar 20, 2023
Comment on lines
14
to
16
| if (isHappy) { | ||
| return "I am happy"; | ||
| } else { |
There was a problem hiding this comment.
There's a pattern in programming to simplify if .. else statements. You can rewrite this block as follows:
if (isHappy) {
return "I am happy";
}
return "I am not happy";
the pattern is called return early pattern, and you can read more here https://medium.com/swlh/return-early-pattern-3d18a41bba8
berkeli
reviewed
Mar 20, 2023
Comment on lines
+44
to
+52
| function printOddNumbers(limit) { | ||
| let i = 1; | ||
| while (i <= limit) { | ||
| if(i % 2 !==0) { | ||
| console.log(i); | ||
| } | ||
| i++; | ||
| } | ||
| } |
There was a problem hiding this comment.
this works fine, but you could make it 2x more performant by skipping over even numbers. For example:
Suggested change
| function printOddNumbers(limit) { | |
| let i = 1; | |
| while (i <= limit) { | |
| if(i % 2 !==0) { | |
| console.log(i); | |
| } | |
| i++; | |
| } | |
| } | |
| function printOddNumbers(limit) { | |
| let i = 1; | |
| while (i <= limit) { | |
| console.log(i); | |
| i+=2; | |
| } | |
| } |
berkeli
reviewed
Mar 20, 2023
Comment on lines
+59
to
+61
| if (price1 < 0 || price2 < 0) { | ||
| return "Invalid price for an item"; | ||
| } |
There was a problem hiding this comment.
Nice add, always good to handle edge cases even if the exercise didn't mention it
berkeli
reviewed
Mar 20, 2023
Comment on lines
+63
to
+67
| let totalPrice = price1 + price2; | ||
| let discount = Math.min(price1, price2); | ||
| let discountedPrice = totalPrice - discount; | ||
|
|
||
| return discountedPrice; |
There was a problem hiding this comment.
I think this can be simplified with the following:
Suggested change
| let totalPrice = price1 + price2; | |
| let discount = Math.min(price1, price2); | |
| let discountedPrice = totalPrice - discount; | |
| return discountedPrice; | |
| return Math.max(price1, price2); |
What do you think?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?