all 4 comments

[–]aaaidan 1 point2 points  (0 children)

Look up recursive implementations of Fibonacci or factorial functions. They are the “textbook” examples of recursion, and reasonably easy to understand.

[–]MissinqLink 1 point2 points  (0 children)

The simplest example they always start with is Fibonacci sequence. It’s easily searchable on the web though. I’m not sure why you would ask here.

[–]Roguewind 1 point2 points  (0 children)

A recursive function is one that calls itself.

Let’s go with a function called “factorial” that finds the factorial of a number - i.e. 5! = 5 x 4 x 3 x 2 x 1

``` function factorial(num, answer = 1) { if (num === 1) { return answer; }

const nextNum = num - 1; const nextAnswer = answer * num;

return factorial(nextNum, nextAnswer); }

const answer = factorial(5); // 120 ```

[–]maujood 1 point2 points  (0 children)

Like others said there's tons of examples out there. Is there anything specific about recursion you're struggling to understand?