Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
it is clever but the readability of it is not that great... the condition and output of if statement is on the same line, i would say is not best practice beacause the author has sacrificed readability for realestate.
Best practices are the generally accepted manner of writing code. Doesn't really matter what that manner is, as long as a lot of people agree on it. The fact that 14 people all wrote this code in almost exactly the same manner makes it a pretty good estimate of what best practices are, at least for the problem at hand.
I disagree with you on the regexp bit. It's a computational efficiency hellhole to do that. It simply wouldn't work well with (for example) parsers, where the order of matches is often very important and implementing a regexp in that way is entirely unfeasible. However, generally when you're writing a parser, you don't write a single regexp, you generate one. I get what you're saying though, and that's one reason named captures were added as a feature to a lot of regexp engines. A quick Google search even tells me that Python (surprisingly not Perl) was the first implementation that included it.
IMO
Best practice is when a code is small, efficient and easy to understand.
When people refactor, they sometimes make the code smaller but a bit unreadable. That's not the best practice.
Sometimes people add unneeded generalisation, that is also not the best practice.
For example a function that returns if a regex pattern contains 3 groups of chars is better done as 3 separate regex tests for each group. Even if that is 3 times more tests, the code will be much easier to read.
I don't really like the term "best practice", as I can't point my finger to what exactly it means. It would be better if you had something to compare this code with. Is it something in particular that you don't like here?
I can't really find a better implementation going through the solutions. Maybe using the variable names shorter, longer would add some readability, but the scope of the problem is so small that maybe being more concise is better.
That's exactly the point, why this solution isn't the best.