Javascript recursion from Eloquent Javascript

懵懂的女人 提交于 2019-11-27 05:33:22

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!