Skip to content

ITP-JAN-25 | WM| Hatef Eidi | Module-Data-Flows | Array Destructuring | Week-1 #167

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 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const personOne = {

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
function introduceYourself( { name, age, favouriteFood }=personOne) {

Choose a reason for hiding this comment

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

Nit: Try to keep spacing consistent throughout your code. It makes it easier to read and maintain. 🙂
function introduceYourself( { name, age, favouriteFood } = personOne )

console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
Expand Down
15 changes: 15 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ let hogwarts = [
occupation: "Teacher",
},
];

// - In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house.
// - Use object destructuring to extract the values you need out of each element in the array.
function gryffindorMembers(hogwarts) {
return hogwarts.filter(({ house }) => house === "Gryffindor")
.map(({ firstName, lastName }) => `${firstName} ${lastName}`);
}
console.log(gryffindorMembers(hogwarts));
Copy link

@jenny-alexander jenny-alexander Apr 20, 2025

Choose a reason for hiding this comment

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

nit: I would output text explaining what the output is.
console.log('Gryffindor members are:', gryffindorMembers(hogwarts)).

// - In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of teachers who have pets.
// - Use object destructuring to extract the values you need out of each element in the array.
function teachersWithPets(hogwarts) {
return hogwarts.filter(({ occupation, pet }) => occupation === "Teacher" && pet)
.map(({ firstName, lastName }) => `${firstName} ${lastName}`);
}
console.log(teachersWithPets(hogwarts));
Copy link

@jenny-alexander jenny-alexander Apr 20, 2025

Choose a reason for hiding this comment

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

nit: I would output text explaining what the output is.
console.log('Teachers with pets are:', teachersWithPets(hogwarts)).

22 changes: 22 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,25 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

//We want to log QTY, ITEM, and TOTAL once at the beginning of the receipt
//Then we want to log each item in the order array, and align the columns
//Finally, we want to log the total price of the order
function printReceipt(order){
let total=0
console.log("QTY ITEM TOTAL")
console.log("--------------------------------");

order.forEach(({itemName, quantity, unitPricePence})=>{
let totalItem=quantity*unitPricePence/100
total+=totalItem
console.log(
`${quantity.toString().padEnd(7)} ${itemName.padEnd(21)} £${totalItem.toFixed(2)}`
);
})
console.log(`Total: ${total.toFixed(2)}`)
Copy link

@jenny-alexander jenny-alexander Apr 20, 2025

Choose a reason for hiding this comment

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

The readme required output different than what your PR is showing:

  1. The readme does not have the '----------' under the column headers.
  2. The readme file shows a space between the last item and the final total. Can you make this small change?
  3. The readme does not show the item.length being output. Can you update your code to reflect the expected result from the readme?

}
printReceipt(order);
// console.log("QTY ".length) ouais c'est 8
console.log("ITEM ".length)
// ouais c'est 22
2 changes: 0 additions & 2 deletions Sprint-1/destructuring/exercise-3/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

## Expected result

```
QTY ITEM TOTAL
1 Hot Cakes 2.32
2 Apple Pie 2.78
Expand All @@ -18,4 +17,3 @@ QTY ITEM TOTAL
4 Hash Brown 1.60

Total: 14.50
```