Ad
  • Custom User Avatar

    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 from num to 1.
    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.