This was my second kata of the week and it felt a lot better than the last. I learned more about regex writing and specifically how Regexp wraps text with the “/” characters. That one messed me up because it had an entirely different meaning than I intended. I also used slice instead of split(“”) and pop in order to grab the last item in a string. That is cleaner and (I think) faster.
Here’s the problem on codewars: Triple Trouble.
Here’s my code:
This was an interesting problem mostly from a “using regex” aspect. It required me to learn a bit more about capture groups. One thing I didn’t initially take into consideration is that the match() method returns a nice object when there is no greedy tag, and it returns a list of matches when there is a greedy tag. That was surprising and required me to shift my strategy in order to iterate through the list, slicing one char from the start as opposed to simply calling the object property that was the repeated character.
Surprisingly the highest voted answers were only a bit smaller than mine, and they mostly seemed to use similar methods. They did end up combining a lot more logic and regexes in one line, and they used regex formats that I haven’t seen before as well. .test() is one that I remember seeing.