I consider myself an advanced beginner in programming. I lack a lot of knowledge in best practices, gotchas, elegance... let alone algorithms, opti...
For further actions, you may consider blocking this person and/or reporting abuse
Very nice post, sounds like you have learned a lot! The destructuring is available also in Python and Clojure, but I tend to forget it all the time 🤦♀️ For example when solving the Advent of Code puzzles 😄
Great post! I haven't had time to participate in the Advent of Code, but I still occasionally enjoy reading from others doing the tasks. I have one suggestion. Not necessarily an improvement, but an alternative way for the for loop for checking the hex code validity. This is also using the
includes
Ilê Caian already mention about:The
slice
function gives a sub array starting from the index 1, so it will omit the # sign.every
function for the array iterates over every character of the array and returns true if all of the iterations return true. In case any of the iterations return false, the whole function returns false.Ah, clever! Thanks for the code example!
Awesome post! I'm also taking adventures at the Advent of Code this year and I think I can give some thoughts too:
Array.includes()
: returnstrue
orfalse
instead of the indexconst
on variables that do not change (consider capitalizing some of them too)I would also suggest using some of RegExp here and there. You can make good use of
.match()
and.replace()
where you need to find patterns in repetitive strings. As an example, you can check the usage of.replace()
at this solutionKeep coding!! 😄
Very good tips, thank you! I should've noticed
includes
and when I can useconst
. Actually, in my day 7 code (bags...) I useincludes
!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)
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!I don't know why but my first thought with the validation on day 4 was RegEx
Oh yes, I would've done regex but I didn't know how. 🙈 I'd come across regex in a search and replace usage only. I've improved a lot of my code "retroactively" so I'll probably look into regex solution as well because I like regex. 😄
Such luck: there is a post titled "How to use Regular Expressions in JavaScript" under Trending on DEV. Gotta check that out.
Regex is something yeah :D this site is great for testing out statements, also has useful tips :)
Thanks for the link!
RegexEr is the best!
I highly recommend learning Regex, it will be very handy one day or another! And I don't even mean the more advanced features, just the basics would be a huge step forward!
You did an awesome job on days 1-5. Hoping to hear again on 6-[...]!
Destructuring........ facepalm for me there too. Would have saved time on that challenge.
Nice one, thanks.