PacktPublishing/Node.js-Design-Patterns-Third-Edition

Are there answers for the exercises

stuartambient opened this issue ยท 19 comments

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

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? ๐Ÿ˜‰

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.

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

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.

@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!

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

@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

@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, @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, I added your solution to the list :)

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

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 :)

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?

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)?

@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!

@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.

@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