Can't Wrap My Head Around This This Recursion Example
So there is this recursion example in chap 3 of Eloquent JavaScript, it goes like this: Consider this puzzle: by starting from the number 1 and repeatedly either adding 5 or multip
Solution 1:
The first time you call findSolution()
it will return the result of the last line of that function find(1, "1")
. In that case "1" is history, which is being set by calling find
. The value of current
is 1, which was the first parameter in find(1, "1")
The important thing to understand is that you are calling a function that is calling a newly defined function find
. The results of that function, which will recursively call itself is an exercise left to the reader (you). Whatever that result is will be returned by findSolution
.
Post a Comment for "Can't Wrap My Head Around This This Recursion Example"