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.
I mean, as far as solving the solution without using any built-in methods goes, this works well.
Most people find switches easily readable, so that's a highly subjective point. It might just be that you're not familiar with them.
Also switches exist across languages, they're not by any means exclusive to JS.
This is incorrect. I didn't take the time to read through all of the code in jsfiddle, but every resource will typically tell you that if/else is good for two discrete values, but switch statements win for performance for anything larger than two values. That said it's really miniscule in performance and the best option is the one that's most readable.
https://www.oreilly.com/library/view/high-performance-javascript/9781449382308/ch04.html#:~:text=As%20it%20turns%20out%2C%20the,than%20it%20is%20for%20switch%20.
https://stackoverflow.com/questions/767821/is-else-if-faster-than-switch-case
https://www.geeksforgeeks.org/switch-vs-else/
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
And the award for longest code goes to...
So I understand what you're doing here but your time complexity is exponential, which isn't great. There are ways to solve this with linear complexity.
Hmm, I see what you did there.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This is awesome. I'm pretty new and was struggling with this problem for a minute. I liked my answer but it's always so cool to see things put so succinctly! I feel like I learn just as much from practicing my own kata as I do from studying how other people achieve theirs.