Bi-Weekly Learning Update (18!)

I’ve been working on the freeCodeCamp Intermediate Algorithm Scripting challenges for the past couple of weeks. I wanted to do that instead of jumping straight back in to the Twitch tv project, just to ease myself back into it.

I often set myself little goals, not just for coding, but in other parts of my life as well, and I decided a couple of weeks ago that I wanted to become more comfortable with regular expressions. I spent a few hours watching videos- mostly by Coding Rainbow/Train this guy: Daniel Shiffman! If you’ve ever watched a coding video and thought to yourself “man, this guy is really excited about coding”, it was likely him. I wasn’t entirely convinced at first, but the guy obviously loves what he does, and his high energy keeps you engaged and interested for the whole video [or videos, if you’re me!] The videos definitely took a lot of the mystery out of regular expressions, and explained literal characters, meta characters, and modifiers.

After watching the videos I went onto my next freeCodeCamp challenge, Spinal Tap Case. Spinal-case, also called kebab-case, is the naming convention [like camelCase] of separating words with dashes, and this challenge is about converting strings to spinal case. This is Spinal Tap is an amazing film, and while I’m pretty sure it was just included as a pun, I appreciated the opportunity to think about it and will probably be watching it again soon!

I completed the challenge [I mean, I got all the tests to pass,] but, full disclosure, I wasn’t happy with the code; it was a longer function than it should have been- somehow I ended up needing a for loop! I looked around online and found that people were using much shorter functions, so the following day I tackled the challenge again, and this time I was much happier with the result!

I started writing comments at the top of each challenge listing the steps I needed to follow to complete it, so it was easy to see what I had done, and what I needed to do. Originally, I tried to replace any character that wasn’t a letter with a space, convert camel case to a regular string, then replace spaces with dashes. I had a lot pf problems with that, and my solution wasn’t really practical, but it worked… I was kind of doing it backwards, but all I was really doing was making it much more complicated than it needed to be! When I redid the challenge I created two regular expressions: one to separate camel case into a regular string, and the other to change any spaces and underscores to dashes. MUCH better!

I’ve gotten into the habit of checking the solution code after I’ve completed a challenge, so that in cases like this I can see where I’ve gone astray. I don’t copy code from the solution, but I have another look at it bearing in mind the explanations from other people who have completed it, and usually have an “ah-ha” moment, and cut the number of lines in half!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s