-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
NW6| BakhatBegum |Module-JS3| Feature/destructuring| Sprint-3 #302
base: main
Are you sure you want to change the base?
NW6| BakhatBegum |Module-JS3| Feature/destructuring| Sprint-3 #302
Conversation
|
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.
Great work implementing the features, Bakhat! 🚀
I'm going to move this task back to the backlog, because there's some more opportunities to use destructuring. That will help to make sure you understand it inside out, let me know if you have any more questions 🙂
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.
Great work using destructing in the function's parameters Bakhat! Just make sure you don't change lines that aren't part of the task, for example, line 13 could have stayed in.
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.
Be careful of changes that aren't part of this exercise Bakhat. Keeping pull requests nice and tidy is a good habit to get into 🙂
@@ -70,3 +70,22 @@ let hogwarts = [ | |||
occupation: "Teacher", | |||
}, | |||
]; | |||
|
|||
let { firstName, lastName, house, pet} = hogwarts; |
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.
We don't need this information in the global scope, so there's no need to destructure here 🙂
function property(array){ | ||
let gryfindorHouse = array.filter(hogwarts => hogwarts.house === "Gryffindor") //filter mean to give only the elements that pass a certain condition specified by a provided function | ||
let getAllName = gryfindorHouse.map( hogwarts =>`${hogwarts.firstName}${hogwarts.lastName}`); | ||
return getAllName; | ||
} | ||
console.log(property(hogwarts)); | ||
|
||
function whoHavePet(array){ | ||
let findPet = array.filter(hogwarts => hogwarts.pet !== null) | ||
let getPet = findPet.map( hogwarts =>`${hogwarts.firstName}${hogwarts.lastName}`); | ||
return getPet; | ||
} |
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.
There's some great use of filter
and map
functions here, Bakhat!
Just think carefully about where we could have used destructuring. For example, on line 77, we use house
as part of the lambda function. Instead of writing hogwarts
before =>
, what else could you use?
@@ -6,3 +6,26 @@ let order = [ | |||
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, | |||
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, | |||
]; | |||
|
|||
let { quantity, itemName, unitPrice } = order; |
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.
Like in exercise 2, there's no need to destructure here 🙂
function itemList(item){ | ||
const subtitleItems = ["QTY", "ITEM", "TOTAL"]; | ||
item.forEach(order => { | ||
const totalOrder = (order.quantity * order.unitPrice).toFixed(2); | ||
subtitleItems.push(`${order.quantity}\t${order.itemName}\t${totalOrder}`); | ||
}); | ||
|
||
return subtitleItems.join('\n') | ||
|
||
} | ||
console.log(itemList(order)); | ||
|
||
|
||
function totalPrice(num) { | ||
const total = num.reduce((accumulator, currentValue) => accumulator + currentValue.unitPrice * currentValue.quantity, 0); | ||
return `total: ${total}` | ||
|
||
} |
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.
There's some missed opportunities to use destructuring here. Like in exercise 2, take a look at your lambda functions.
Instead of accessing properties of objects like order.quantity
, is there any other way we can get the quantity
of the order?
Learners, PR Template
Self checklist
Changelist
excercise-1
What is the syntax to destructure the object
personOne
in exercise.js?introduceYourself
to use destructuring on the object that gets passed in.exercise-2
exercise.js
write a program that will take thehogwarts
array as input and display the names of the people who belong to the Gryffindor house.exercise.js
write a program that will take thehogwarts
array as input and display the names of teachers who have pets.exercise-3
exercise.js
, you have been provided with a takeout order. Write a program that will print out the receipt for this order.Questions
Ask any questions you have for your reviewer.