Recursive Conditions - Missing Base Case
I've wrapped my head around recursion, and am now trying to put it into into practical application without a stack overflow (or doing the Fibonacci sequence (again)! Pun intended.
Solution 1:
It depends on what terms you're using, but http://en.wikipedia.org/wiki/Recursion_%28computer_science%29#Recursive_functions_and_algorithms (for example) has the base and terminating cases meaning the same thing. In your code, the termination case is the base case as it is what produces the result.
As a side note, you could do this:
alert(getIt(myArray, 0));
instead of this:
var tries = 0;
alert(getIt(myArray, tries));
Post a Comment for "Recursive Conditions - Missing Base Case"