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

NW-6 | AREEB-SATTAR | JS3| [TECH ED] Array Destructuring | WEEK-3 #306

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

Conversation

areebsattar
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

Briefly explain your PR.

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.

This is great work on destructuring in lambda functions, Areeb! I'm just going to put this ticket back on the backlog to make sure you've got the hang of exercise 1.

It needs us to use destructuring inside the function's parameters, so it will on the same line as the function declaration itself. Look out for some examples under "Unpacking properties from objects passed as a function parameter" on this MDN Web Doc

Copy link
Member

Choose a reason for hiding this comment

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

Great use of destructuring, Areeb!

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 two files from the book-library/ directory that have sneaked their way into this PR. A good habit is to make sure you're on the correct branch when you commit 🙂

Copy link
Author

Choose a reason for hiding this comment

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

I did realize this later, I will try to be more careful with this in future


let sum = 0;

order.forEach(({ itemName, quantity, unitPrice }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Excellent!

@areebsattar
Copy link
Author

I have made some changes to excercise-1 again. I hope this time it is how it's supposed to be

function introduceYourself(___________________________) {
let { name, age, favouriteFood } = personOne;

function introduceYourself(personOne) {
Copy link
Member

@JayMayer JayMayer Mar 27, 2024

Choose a reason for hiding this comment

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

I think this would be a good time to introduce a new way to use destructuring. This function takes a parameter that is an object. We know the object will be a person that has a name, age, and favourite food.

Because we know exactly what information we need from the object, we can destructure it right here as we define the function.

function introduceYourself({ name, age, favouriteFood }) will give us the name, age, and favouriteFood to use inside of the function block.

Every time we pass a person object to the function, the code will now magically extract those properties from the object without us doing any extra work! 🚀

Let me know if that makes sense @areebsattar

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for this explanation, it does make it clearer and I believe what we were doing with props in React also made it clearer as well.

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