Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

North_West_4 - Terry Calderbank - JavaScript_Module_2 - Week_1#98

Closed
Texx45 wants to merge 9 commits into
CodeYourFuture:mainfrom
Texx45:main
Closed

North_West_4 - Terry Calderbank - JavaScript_Module_2 - Week_1#98
Texx45 wants to merge 9 commits into
CodeYourFuture:mainfrom
Texx45:main

Conversation

@Texx45
Copy link
Copy Markdown

@Texx45 Texx45 commented Jul 22, 2021

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name: Terry Calderbank
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy? Nothing

  • What did you find hard? Everything

  • What do you still not understand? How to full use the array methods to access objects

  • Any other notes?

The estimation of 3 hours to complete the homework was way off. It works out at less than 20 mins per exercise, now this is a problem when you are trying to manage your time using the estimates given.


View rendered .github/pull_request_template.md
View rendered GRADING.md
View rendered HOW-TO-GET-HELP.md
View rendered HOW-TO-SUBMIT.md
View rendered HOW_TO_MARK.md
View rendered README.md

@SteveLeicester
Copy link
Copy Markdown

Thanks Terry

1-writer.js

Looks great. I'm a fan of arrow functions so like the way you have done that. Note you can chain directly too. Often a matter of preference and readability. One guide is that if you filter into a variable will that variable be used again further down in the code. If not you can chain but yes always consider how readable the code is (by other humans). Too much chaining can also make code obscure.

function logDeadWritersInTheirForties() {
let filteredDeadWriters = writers.filter((writer) => writer.age >= 40 && writer.age < 50 && !writer.alive).
forEach((element) => console.log(Writer ${filteredDeadWriters[0].firstName} ${filteredDeadWriters[0].lastName} died at ${filteredDeadWriters[0].age} years old.) );
}

2-eligible-students.js

I take your point in eligibleStudents but your solution is perfectly fine. But how do you do it directly? Think about this

  1. Get the stuff you want (filter)
  2. Turn the stuff you want into something else of interest (should make you think of map)

This is a very common pattern - it will certainly keep reappearing. So

function eligibleStudents(attendance) {
return attendance
.filter(student => student.attendance >= 8)
.map(student => student.name);
}

3-journey-planner.js

Your implementation looks great. Can this also be done without creating a variable and populating it through push? So here is a thought. Get all the locations (they are the keys which you have looped through). Then filter according to the required transport mode. How to get the keys of in object in one go. Like this

Object.keys(myObject)

So it's a bit of a trick but something like

const journeyPlanner = (locations, transportMode) => Object.keys(locations).filter(location => locations[location].includes(transportMode));

4-water-bottle.js

I can see one or two issues here. Avoid returning something when it's not needed or expected

fillUp: function () {
return (this.volume = 100); // calling this function should completely fill your bottle (volume = 100);
},

So we're changing the state of the bottle (object) but not expecting anything back - its just an operation on the bottle. So

fillUp: function () {
this.volume = 100; // calling this function should completely fill your bottle (volume = 100);
},

More serious are the question functions isFull and isEmpty. So you have

isFull: function () {
if (this.volume === 100) {
return true;
} // this function should return true if your bottle is full;
},

What if the condition fails? It looks like it just falls out of the function without returning so care is needed here. In fact a neat way is simply to return the test, which can be true of false. So

isFull: function () {
return this.volume === 100;
},

5-groceries.js

Wow - a neat trick for removing duplicates with a set and then destructuring. I'm glad you commented otherwise I'd have been puzzled. I never had cause to use sets but yes sets don't have duplicates. Like it.

6-people-I-know.js

Much professional looking code in here. Possibilites of chaining filter and map here and there but be guided by clear readable code.

7-recipes.js

Does what it says on the tin. Excellent.

8-reading-list.js

Again - an array of objects nicely done. On the tin again :-)

9-budget.js

Also very good stuff.
Here is a very tight way of doing it using something called reduce. This combines multiple items into a single item. And as I like arrow functions you can do

/* reduce is called for each entry in the array (second argument) and a value returned from the previous call */
/* (first argument) unless it is the first time in which case the initial value (0) is used. */
const getBudgets = (peopleArray) => peopleArray.reduce((runningSum, person) => runningSum + person.budget,0);

This is not to detract from the approach you took which is clear and understandable. More to add to the different ways of dealing with arrays (or lists).

10-cheap-diner.js

Great approach - I'm glad you thought about using sort - giving a nice way of doing it.

11-choose-your-own-adventure.js

OK - it's good to learn from others. Often it can be really difficult to just get going on something. Where to start. In the real world developers are already working on something that is already there. And the key is to have clear code to help others in that process.

All in all a cracking piece of work Terry so thanks for that.

Steve

@Texx45
Copy link
Copy Markdown
Author

Texx45 commented Jul 31, 2021

Hi Steve, thanks for the feedback it really helps and is good for reference. I really found this week tough as these were pretty new concept to me and I had only ever seen them in really basic forms, not used on objects or chained for filtering multiple items. I feel I learnt a lot although could have done with another week on them to really drive them home.

Once again thanks for taking the time to go through them it really is appreciated!

@github-actions
Copy link
Copy Markdown

Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback.

@github-actions github-actions Bot added the Stale label Sep 12, 2021
@github-actions github-actions Bot closed this Sep 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants