Skip to content

Conversation

@MohammedNaru
Copy link

@MohammedNaru MohammedNaru commented Nov 28, 2025

Feature/destructuring Pull Request

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Refactored changes to the 3 exercise files

Questions

No Questions for reviewer.

@github-actions
Copy link

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.

@MohammedNaru MohammedNaru changed the title Implement destructuring in introduceYourself function and add Gryffindor member and teacher retrieval functions West Midlands | 25-ITP-Sep | Ali Naru | Sprint 1 | feature/destructuring Nov 28, 2025
@github-actions
Copy link

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.

@MohammedNaru MohammedNaru added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Flows The name of the module. labels Nov 28, 2025
Copy link
Contributor

@cjyuan cjyuan left a 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');
Copy link
Contributor

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');

Comment on lines +14 to +24
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)}`);
})
Copy link
Contributor

@cjyuan cjyuan Nov 29, 2025

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)));
  })

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Data-Flows The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants