Staying sharp means consistent practice. There are so many facets of technology that could occupy my attention, but I feel that it is important to always sharpen the tool that is programming. Solving programming puzzles is a matter of keeping logical reasoning skills strong, and it’s also a lot of fun. The most recent problem that I have been working on is fairly simple, but I decided to write in javascipt for the first time in a while.
My solution involves using regular expressions and looping over each string. I apply a filter that only allows letter characters to be evaluated. Each character is pushed into two arrays. Each array is built from the first letter up or backwards from the last letter forward. Afterwards, I compare each array (as a string) and if both strings are identical, then the argument is a palindrome (return true).
Here’s a peek at my solution:
Regular expressions shorten a lot of English language problems into one-liners that confuse the naked eye, but I enjoy writing them and the time that RegExs save are well worth the time. If you’re just wrapping your head around regular expressions, check out rubular. This website offers an unlimited sandbox testing environment for anyone dipping their toe in regular expressions.