-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: main
Are you sure you want to change the base?
Changes from all commits
2d7bdd6
ee46984
f0cda1c
088ca98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would output text explaining what the output is. |
||
// - 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would output text explaining what the output is. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The readme required output different than what your PR is showing:
|
||
} | ||
printReceipt(order); | ||
// console.log("QTY ".length) ouais c'est 8 | ||
console.log("ITEM ".length) | ||
// ouais c'est 22 |
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.
Nit: Try to keep spacing consistent throughout your code. It makes it easier to read and maintain. 🙂
function introduceYourself( { name, age, favouriteFood } = personOne )