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.
Each time
function shortestStepsToNum(num)
is called recursively,num
gets updated (by dividing by 2). So yes -num
decreases with each recursive call, until the base condtition is met (if (num < 3)
). We go backwards fromnum
to1
.Be careful with these operators: increment
++
decrement--
. They increase and decrease by 1. In this kata,num
gets decreased not by 1, but by assigning it new value ===num/2
.I guess the "ticks++" you mentioned, in this very solution this operation takes place here:
return 1 + shortestStepsToNum(next);
.return 1
adds a step with each recursive call.