-
-
Notifications
You must be signed in to change notification settings - Fork 142
West Midlands | 25-ITP-Sep | Ali Naru | Sprint 1 | feature/destructuring #333
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
…dor member and teacher retrieval functions
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Wrong number of parts separated by |s If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
cjyuan
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.
Code looks good.
| ]; | ||
|
|
||
| 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.
A long statement that chains multiple methods/functions becomes more readable when written across multiple lines, placing each method/function on its own line. For example,
const gryffindorMembers = arr
.filter(({ house }) => house === "Gryffindor")
.map(({ firstName, lastName }) => `${firstName} ${lastName}`)
.join('\n');| const receiptLines = order.map(({itemName, quantity, unitPricePence}) => { | ||
| const itemTotalPounds = (quantity * (unitPricePence / 100)); | ||
| qtyWidth = Math.max(qtyWidth, String(quantity).length); | ||
| itemWidth = Math.max(itemWidth, itemName.length); | ||
| return { itemName, quantity, itemTotalPounds }; | ||
| }) | ||
| console.log('QTY'.padEnd(qtyWidth+4), 'ITEM'.padEnd(itemWidth+3), 'TOTAL'); | ||
| receiptLines.forEach(({itemName, quantity, itemTotalPounds}) => { | ||
| total += itemTotalPounds; | ||
| console.log(String(quantity).padEnd(qtyWidth+4), itemName.padEnd(itemWidth+3), `${itemTotalPounds.toFixed(2)}`); | ||
| }) |
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.
Here is an alternative approach to express the code:
// Calculate reserved width first
const qtyWidth = 4 + Math.max(3, ...order.map(({quantity}) => String(quantity).length));
const itemWidth = 3 + Math.max(4, ...order.map({itemName}) => itemName.length));
// Prepare a helper function to construct a formatted string
const formatStr = (qty, name, total) =>
`${qty.padEnd(qtyWidth)}${name.padEnd(itemWidth)}${total}`);
console.log(formatStr('QTY', 'ITEM', 'TOTAL');
let total = 0;
order.forEach(({itemName, quantity, unitPricePence}) => {
const subtotal = quantity * unitPricePence / 100;
total += subtotal;
console.log(formatStr(quantity, itemName, subtotal.toFixed(2)));
})
Feature/destructuring Pull Request
Self checklist
Changelist
Refactored changes to the 3 exercise files
Questions
No Questions for reviewer.