From the course: Learning Functional Programming with JavaScript ES6+

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Recursion

Recursion

- [Instructor] All right, so now that we've taken a look at currying impartial application, let's move on to the next advanced concept, which is recursion. So I'm going to create a new file here called recursion dot js. All right, and put simply, recursion is when a function calls itself in order to solve a problem. Now, there are many problems that can actually be solved more easily using recursion than without recursion, but we're just going to stick to a few simple examples here. So first things first, let's take a look at how to recreate something like a simple loop using recursion. I'm going to call this something like countdown. And what this function is going to do is it's simply going to take some argument, and without using a for loop, it's going to count down from that number, logging each number that it gets to along the way, right? So if we pass in 10, it's going to log out 10, nine, eight, seven, six, all the way down to zero, and then we'll have it say, blast off or…

Contents