DEV Community

Discussion on: What I've learned from the Advent of Code so far (days 1-5)

Collapse
 
minna_xd profile image
Minna N.

Very good tips, thank you! I should've noticed includes and when I can use const. Actually, in my day 7 code (bags...) I use includes!

Thank you also for that code sample! I didn't know you can assign the groups into variables like that. 👍

A question which is either "hey, I'm able to give you a suggestion too!" OR there's some optimization magic going on that I don't know about. About the regex, you have:

/(\d*)-(\d*) (\w): (\w*)/g,

Is there a reason why you use * instead of +? Why not:

/(\d)-(\d) (\w): (\w+)/g,

(or \d+ in case the numbers are double or more digits)

Collapse
 
caiangums profile image
Ilê Caian

Thanks for noticing it! It's true that I could've used + instead of *!

About maintaining \d, I didn't see if the file has values with more than 1 digit, but with * or + will cover it! 😄

It's just a habit using * instead of + and maybe it could be optimized as you said!