Javascript recursion from Eloquent Javascript

1) If you look at the code, the function “findSolution” is composed of two parts: a method definition “find”, and a call to that method “return find(1, “1”)”. The definition, in itself, won’t produce computing unless it is called. So, the first expression that is actually executed is “find(1, “1”)”. It’s the starting point.

2) OR statements are executed in their reading order, so “find(start + 5, …)” will be first executed, and then only if it does return null (that is, it hasn’t find the solution) the next statement “find(start * 3, …)” is going to be executed. Due to recursion, you can have any number of “+5” exection before a “*3” being executed, depending on the target of course.

Leave a Comment