1 min readApr 27, 2019
Hi catprog!
Your solution is actually good. I used switch/case
because it’s the only actual alternative for (kind of) “patter matching” in JavaScript.
I think that some implementations are just about personal preferences.
About loops: there are certain problems that can be solved easier using recursion or declarative code (map
as an example).
It is important to know that there are some alternatives to loops, ’cause once you’re writing multiple nested for loops, your code will exponentially become harder to understand, maintain and document. Sometimes, recursion or functors can be easier to adopt, and it’s important to know them!