-
-
Notifications
You must be signed in to change notification settings - Fork 142
London | 25-ITP-Sep | Imran Mohamed | Sprint 1 | Feature/destructuring #327
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
base: main
Are you sure you want to change the base?
Conversation
ckirby19
left a comment
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.
Great work! I just added come comments around readability
| //task 1 | ||
| function getGryffindorMembers(arr) { | ||
| let gryffindorMembers = []; | ||
| arr.forEach(({ firstName, lastName, house }) => { |
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.
As an extension: could you show me how you can use filter and map on an array to do this?
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.
Used filter and map for both functions in this exercise
| function printReceipt(order){ | ||
| let total = 0 , qtyWidthMax = 3, itemWidthMax = 4 | ||
| const receiptLines = order.map(({itemName, quantity, unitPricePence}) => { | ||
| const itemTotalPounds = (quantity*unitPricePence/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.
Generally, we try to keep space around an operator to make the code easier to read. Also, just to make the code easier to read, it is better to use brackets to show the order of operation that you want. For example, is it not clear whether you intend to have:
- quantity * (unitPricePence/100) OR
- (quantity * unitPricePence) / 100
In this instance, it does not actually matter, as mathematically they are equivalent. But it is a good habit to create to improve your code readability
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.
Noted and amended
| ]; | ||
|
|
||
| function printReceipt(order){ | ||
| let total = 0 , qtyWidthMax = 3, itemWidthMax = 4 |
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.
Just formatting: We usually don't add a comma after a number like you have with total = 0 ,
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.
Noted, have declared and assigned variables individually to aid in readability.
…e filter and map for improved readability
|
|
||
| //task 1 | ||
| function getGryffindorMembers(arr) { | ||
| const gryffindorMembers = arr.filter(({ house }) => house === "Gryffindor").map(({ firstName, lastName }) => `${firstName} ${lastName}`).join('\n'); |
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.
Learners, PR Template
Self checklist
Changelist
I have completed the tasks set out in exercises 1-3 in the Sprint 1 destructuring folder
Questions
I found it unclear if exercise 2 needed a string output, or a log as the task was to display the desired names. As such I have logged these to the console, should I have been outputting strings instead?