Skip to content

WM | 25-ITP-May | Abdullah Saleh | Sprint 1 | Array Destructuring #245

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

3bdullah-saleh
Copy link

@3bdullah-saleh 3bdullah-saleh commented Jul 27, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@3bdullah-saleh 3bdullah-saleh added the Needs Review Participant to add when requesting review label Jul 27, 2025
@oluwatunmiisheii oluwatunmiisheii added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Aug 2, 2025
Comment on lines +82 to +89
const hogwartsTeachers = hogwarts
.filter(({ occupation, pet }) => occupation === "Teacher" && pet)
.map(function ({ firstName, lastName, pet }) {
if (pet) {
return `${firstName} ${lastName}`;
}
})
.join("\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion here: the if check in the map is no longer needed; the filter already does two things

  1. Filter out people who are not teachers
  2. Filter out people who don't have pets.

.filter(({ occupation, pet }) => occupation === "Teacher" && pet)

Comment on lines +11 to +15
order.forEach(({ itemName, quantity, unitPricePence }) => {
const itemTotal = ((quantity * unitPricePence)/100).toFixed(2);
billTotal += Number(itemTotal)
console.log(quantity.toString().padEnd(8), itemName.padEnd(18), itemTotal.padStart(5));
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this code by using Array.prototype.reduce instead of forEach with an external billTotal variable.

Reduce is designed to accumulate a value (like the total bill) while iterating over the array, which makes the intent of the code clearer and avoids mutating variables outside the loop.

For more details, you can check out the MDN docs here:
👉 MDN: Array.prototype.reduce

Comment on lines +74 to +80
const GryffindorHouse = hogwarts
.filter(({ house }) => house === "Gryffindor")
.map(function ({ firstName, lastName }) {
return `${firstName} ${lastName}`;
}).join("\n");

console.log(GryffindorHouse);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor suggestion here,

You can just do a console.log in the map

const GryffindorHouse = hogwarts
  .filter(({ house }) => house === "Gryffindor")
  .map(function ({ firstName, lastName }) {
    console.log(`${firstName} ${lastName}`)
  })

Comment on lines +82 to +88
const hogwartsTeachers = hogwarts
.filter(({ occupation, pet }) => occupation === "Teacher" && pet)
.map(function ({ firstName, lastName, pet }) {
if (pet) {
return `${firstName} ${lastName}`;
}
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just replace the return with a console.log here also

const hogwartsTeachers = hogwarts
  .filter(({ occupation, pet }) => occupation === "Teacher"  && pet)
  .map(function ({ firstName, lastName, pet }) {
    if (pet) {
      return `${firstName} ${lastName}`;
    }
  })
  .join("\n");

@oluwatunmiisheii oluwatunmiisheii added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants