Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
Nothing beats a recursive solution when it comes to elegance IMO.
If you're already in the mood for elegance, why not use a single expression arrow function?
because IMO that's not more elegant.
I think guard clauses should live in the
if
statement that has nothing to do with the rest of the code. I think it is easier to read.But I believe there is no absolute "elegance". Programming is just like art, different people perceive a piece differently.
Mm, Jason's version looks more readable to me. It's laid out a little more like you would if you were matching patterns in Haskell or something.
Here are my 2 cents. It is performant and avoids recursion.