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.
OK, recursion is bad for this.
I solved it in iteration methos.
Exactly.
Too slow in JS and I cannot see a better way for this other than recursion.
When I try (-50) I don't even see the process ends.
How would one begin doing this without using recursion?
The test cases in the javascript translation can be above 1000 so recursion is to slow.
The "Submission timed out" is a Codewars internal thingy (check the GitHub wiki on more information about that). However, a simple recursive will fail, since each non-terminating call will run the function twice, resulting in an exponential runtime (O(2^n)). Just draw the callgraph on a piece of paper and you will notice that it get's quite big for small values like
5
.What language are you using?