Skip to content
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

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

Conversation

BakhatBegum
Copy link

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 COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

excercise-1
What is the syntax to destructure the object personOne in exercise.js?

  • Update the argument of the function introduceYourself to use destructuring on the object that gets passed in.
    exercise-2
  • 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 array destructuring to extract the values you need out of the array.
  • In exercise.js write a program that will take the hogwarts array as input and display the names of teachers who have pets.
  • Use array destructuring to extract the values you need out of the array.

exercise-3

  • In exercise.js, you have been provided with a takeout order. Write a program that will print out the receipt for this order.
  • Log each individual item to the console.
  • Log the total cost of the order to the console.

Questions

Ask any questions you have for your reviewer.

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@JayMayer JayMayer left a 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 🙂

Copy link
Member

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.

Copy link
Member

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;
Copy link
Member

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 🙂

Comment on lines +76 to +87
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;
}
Copy link
Member

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;
Copy link
Member

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 🙂

Comment on lines +12 to +29
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}`

}
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants