Glasgow Class 6 - HERISH TURKI - JS Core 2 - Week 1 #221
Glasgow Class 6 - HERISH TURKI - JS Core 2 - Week 1 #221HereshT wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
shieldo
left a comment
There was a problem hiding this comment.
All good stuff! A few really minor comments and things to think about.
There was a problem hiding this comment.
The approach here is fine, and it's really good that you've been able to use array restructuring here to write simpler and more comprehensible code!
The format of COUNTRY_CURRENCY_CODES_OBJECT would more usually be written as countryCurrencyCodeObject in JavaScript - the capital letters joined by underscores format is more for constants that don't change their values during the lifetime of the program, rather than (in this case) a temporary variable for an object that is being built up and then returned. But that's a minor comment.
|
|
||
| // 2 lovely array methods which I learned here | ||
|
|
||
| const allPantryContents = Object.values(pantry).flat(); |
There was a problem hiding this comment.
This is a neat way to get the ingredients in the pantry into one list! Note that it wouldn't work if the pantry object had other properties too that didn't contain lists of ingredients. But if we know that it never will (and that might be quite reasonable here) then this is a good way to go.
| for (let i = 0; i < recipe.ingredients.length; i++) { | ||
| if (!allPantryContents.includes(recipe.ingredients[i])) | ||
| missingIngredients.push(recipe.ingredients[i]); | ||
| } |
There was a problem hiding this comment.
This works fine, but it would also be quite a good opportunity to use .filter() on the recipe ingredients, e.g.:
const missingIngredients = recipe.ingredients.filter(
(ingredient) => !allPantryContents.includes(ingredient)
);There was a problem hiding this comment.
These functions are fine and clear - it's generally not advised though to change the value of an argument passed in to a function unless that is the explicit purpose of the function. It happens that we expect a number to be passed in here, which won't cause problems to any code calling these functions. In general, though, if we are building a value to be returned, it's best to declare a new variable to hold this new value as we are building it rather than modifying an argument (here balance).
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?