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

Are there answers for the exercises #21

Open
stuartambient opened this issue Nov 13, 2020 · 19 comments
Open

Are there answers for the exercises #21

stuartambient opened this issue Nov 13, 2020 · 19 comments

Comments

@stuartambient
Copy link

Haven't seen them on packt or here, maybe they don't exist ?

@lmammino
Copy link
Collaborator

lmammino commented Nov 13, 2020

Hey @stuartambient, thanks a lot for opening this issue. As of today, we don't have yet a place to collect solutions for the various coding tests.

I think GitHub might be a great place to start collecting some. I just created this wiki page to do that: https://github.com/PacktPublishing/Node.js-Design-Patterns-Third-Edition/wiki/Node.js-Design-Patterns-Third-Edition---Exercise-Solutions

Have you already implemented any solution for these exercises? 😉

@stuartambient
Copy link
Author

Thanks for putting that page up, I'm subscribed and will certainly share my solutions. I just finished reading Chapter 3 and did 3.1 (a minor tweak of a challenge) but 3.2 confused me a bit regarding the number that gets sent to the function. I couldn't tell if it was a number in milliseconds or the number of times setTimeout should run.

Typically I prefer to do a challenge first and then look over others solutions afterward (if they are available). Thanks for the response and creating what is in my opinion an invaluable and comprehensive Node book.

@enricoschaaf
Copy link

enricoschaaf commented Nov 15, 2020

Is this the right solution for 3.1? Or should we clean up the event listener after the start event is emitted in case someone uses .on for this event instead of .once and the file that is processed is so enormous that it takes doesnt make sense to just wait till the instance gets garbage collected.
https://github.com/enricoschaaf/node-js-design-patterns-exercises/blob/main/exercises/3.1/index.js

@stuartambient
Copy link
Author

I just added a line to the for loop in add()

find() {
    for (const file of this.files) {
      **this.emit('starting', `starting regex search on file: ${file}`);**
      readFile(file, 'utf8', (err, content) => {
........
}
Then in call
.addFile('fileA.txt')
  .addFile('fileB.json')
  **.on('starting', message => console.log(`find start message: ${message}`))**
  .find()

Probably would be a good idea for me to add a remove listener at the end.

@mariocasciaro
Copy link
Collaborator

@enricoschaaf that looks like the right solution. I wouldn't overthink too much the cleaning part unless it would cause a memory leak, let's leave Node.js do its job.
Do you want to add your solution to https://github.com/PacktPublishing/Node.js-Design-Patterns-Third-Edition/wiki/Node.js-Design-Patterns-Third-Edition---Exercises-Solutions?

@stuartambient beware of Zalgo when emitting the "starting" event!

@enricoschaaf
Copy link

Sure, is there a way to provide pull requests to wiki's? Could not find any.

@stuartambient
Copy link
Author

@lmammino
Copy link
Collaborator

lmammino commented Nov 16, 2020

@enricoschaaf, @stuartambient I think I finally managed to configure the wiki correctly. Can you tell me if you can see the "edit" button now?

Thanks

@stuartambient
Copy link
Author

@enricoschaaf, @stuartambient I think I finally managed to configure the wiki correctly. Can you tell me if you can see the "edit" button now?

The link went straight to a new page form. I added some stubs so the home page has the stub pages in the right panel. Buttons for edit / new are there as well.

Problem though is the link above is now just a page in the TOC. It didn't keep it as the wiki home page. I think maybe only the repo owner would be able to change it.

@enricoschaaf
Copy link

@enricoschaaf, @stuartambient I think I finally managed to configure the wiki correctly. Can you tell me if you can see the "edit" button now?

Thanks

Works👍

@stuartambient
Copy link
Author

updated my 3.2 if it's helpful - https://gist.github.com/stuartambient/7485f29ace060eb6600ca61195d590a6

@lmammino
Copy link
Collaborator

@stuartambient, I added your solution to the list :)

@stuartambient
Copy link
Author

Solution 3.4 https://gist.github.com/stuartambient/d7f4c16fb7af21b2ae8197bfabcb7ac1
This is the right place to suggest a solution, or no ?

@lmammino
Copy link
Collaborator

I am copying them to this wiki page: https://github.com/PacktPublishing/Node.js-Design-Patterns-Third-Edition/wiki/Node.js-Design-Patterns-Third-Edition---Exercise-Solutions

You should be able to edit it if you want to add more in the future :)

@Jack-Barry
Copy link

Hey @stuartambient and @enricoschaaf, looks like we're all at about the same point in the book. Would either of you be interested in starting a Gitter or something like that to chat about what we're learning and help each other figuring out solutions to the EOC problems?

@lmammino
Copy link
Collaborator

Hey @Jack-Barry, @stuartambient & @enricoschaaf. I love the idea of offering a place for readers to discuss. I just enabled "GitHub discussions" on this repo (https://github.com/PacktPublishing/Node.js-Design-Patterns-Third-Edition/discussions). Do you think this can help you or do you prefer something like a chat (slack or discord style)?

@Jack-Barry
Copy link

@lmammino That should work, I didn't even know about that feature in GitHub. That should make it easier for anyone using this resource to participate without having to have an account for another service.

Thanks for setting it up!

@stuartambient
Copy link
Author

stuartambient commented Dec 20, 2020

@Jack-Barry thanks for reaching out. I also agree that the discussions here would work fine. Personally I've been working slowly through the book. I know that this book has come up in a few recent r/node threads and got positive comments and upvotes.

@Jack-Barry
Copy link

@stuartambient Thanks for the heads up, I'll keep an eye out in r/node. I've started a discussion thread for Chapters 4 & 5 here. I'm reading through Chapter 6 but haven't completed exercise 5.3 or 5.4 yet. 5.3 seems easy enough, 5.4 looks a little more involved so I might not get through it until after the holidays

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

No branches or pull requests

5 participants