-
-
Notifications
You must be signed in to change notification settings - Fork 72
ITP Jan 25 | Katarzyna Kazimierczuk | Data Flows | Sprint 1 #211
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?
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.
Generally it does look like you've understood destructuring well. There may be an issue in the first exercise when using it with function syntax - I would recommend running the exercise.js scripts to check your work. Good work generally though!
@@ -6,7 +6,7 @@ const personOne = { | |||
|
|||
// Update the parameter to this function to make it work. | |||
// Don't change anything else. | |||
function introduceYourself(___________________________) { | |||
function introduceYourself(name, age, favouriteFood) { |
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.
When this script is now run, what happens?
There are three different parameters defined here in the function - the place where the function is called only passes in one argument, which is the personOne
object. This contains fields that happen to be called name
, age
, and favoriteFood
. Restructuring gives us a way to pass a whole object into a function, but for the function to pick out only the fields it needs, and to access them in a simple way (i.e. as name
and age
etc, rather than person.name
and person.age
which can get needlessly repetitive).
I would have a look at this section of the MDN documentation for destructuring in JavaScript, which gives some relevant examples - notice the brace ({
and }
) characters inside the parentheses in the function definition. This kind of syntax is subtle, and a bit magical, but hopefully at some point it will click for you. It's definitely commonly used in JavaScript and TypeScript these days.
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.
of course, it should be ({name, age, favouriteFood}), with the current one will get undefined.
favouriteFood: "Spinach", | ||
}; | ||
|
||
let personOne { name, age, favouriteFood } = personOne |
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.
Close, but this doesn't need the initial personOne
. We're using let
to declare three variables (name
, age
, and favouriteFood
) which are mapped from the fields with those names when the object personOne
on the right hand side of the assignment operator (=
) is destructured, i.e. taken apart into its constituent parts.
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.
It absolutely does not! It's now corrected.
}) | ||
|
||
return teachersWithPets; | ||
} |
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.
When I add the lines:
console.log(sortingHat(hogwarts));
console.log(findTeachersWithPets(hogwarts));
I do get the expected output when running the file. You've used destructuring effectively here to pick out from objects only the specific fields that you need. Good stuff!
|
||
createReceipt(order); | ||
|
||
//I have the receipt in a table format it is not identical to the one in the example but it is a table format :) |
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.
It certainly is a table format :)
Usually when we have an expected format we want to follow that format - but you've done the destructuring part here fine and all the numbers are correct, so this is fine :)
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.