-
-
Notifications
You must be signed in to change notification settings - Fork 83
NW6| BakhatBegum |Module-JS3| Feature/destructuring| Sprint-3 #302
base: main
Are you sure you want to change the base?
Changes from all commits
2c02a40
c42bd75
b023e06
a48af94
1e475f8
3efbd1f
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/array-destructuring/exercise-2/exercise.js" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
const personOne = { | ||
let personOne = { | ||
name: "Popeye", | ||
age: 34, | ||
favouriteFood: "Spinach", | ||
favoriteFood: "Spinach", | ||
}; | ||
|
||
function introduceYourself(___________________________) { | ||
let { name, age, favoriteFood } = personOne; | ||
|
||
function introduceYourself({ name, age, favoriteFood }) { | ||
console.log( | ||
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` | ||
`Hello, my name is ${name}. I am ${age} years old and my favorite food is ${favoriteFood}.` | ||
); | ||
} | ||
|
||
introduceYourself(personOne); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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; | ||
} | ||
Comment on lines
+76
to
+87
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. There's some great use of Just think carefully about where we could have used destructuring. For example, on line 77, we use |
||
|
||
console.log(whoHavePet(hogwarts)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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}` | ||
|
||
} | ||
Comment on lines
+12
to
+29
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. 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 |
||
console.log(totalPrice(order)); | ||
|
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. 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 🙂 |
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.