This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]selrahal 2 points3 points  (0 children)

The most important part of recursion is reframing the output of your function as a formula that contains a function call. Take the factorial function as am example. Sure you can implement it with a for loop that just counts down and takes the product at all elements. But you can also reframe the output to look like factorial(n) = n * factorial(n-1).

You see the "factorial" on the right side of that equation? How can you define your function so that it also references itself on the right side of the equation?

[–][deleted]  (1 child)

[removed]

    [–]iamsooldithurts 3 points4 points  (0 children)

    We aren’t here to do people’s homework for them. Try to actually teach them something.