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.
This comment is hidden because it contains spoiler information about the solution
Damn, I forgot about substr. Well Done!
Agreed. Pure recursion is way too easy to blow up with a big input.
"The number will be passed in as a string of only digits."
Just Perfect!
Why is not it working for me without digits.toString() transformation? :)
Awesome !
it is recursive so solution is the function name and calling itself again inside
Does anybody care to explain this? I don't see where the function iterates through the string. I see it returning the larger of two options, digits[0, 5] and ... this "solution(digits.substr(1)". digits.substr(1) means go from [1] to the end of the string. I don't know what the word solution is doing. Google didn't turn up a method or anything so it looks to me like a variable instantiation.
Here is a nice explanation: http://2ality.com/2015/06/tail-call-optimization.html.
This was the example given: "In the following 6 digit number:
283910
91 is the greatest sequence of 2 digits."
You can see that if you were about to pick the largest from right to left and left to right then 93 would be the return instead, but this picks 91. I think when they say largest "sequence" they mean from left to right only. Does that answer the question you were asking?
This comment is hidden because it contains spoiler information about the solution
may be better using tail call like return tailCall(digits.substr(1, digits.length), max)
'The number will be passed in as a string',the description says it clearly
In case someone tries to run digits.substr(0, 5) on nodejs it won't work directly, instead convert it to a string: digits.toString().substr(0, 5)