On September 14th, 2017, we published revised versions of our Privacy Policy, Terms of Service and Website Use Policy and published a Cookie Policy. Your continued use of Lynda.com means you agree to these revised documents, so please take a few minutes to read and understand them.

Recursive example

Keyboard Shortcuts

Using a function that sums three numbers as an example, Kyle demonstrates how to take a non-recursive operation and add recursion. He also shows a cleaner version of the recursive function which utilizes ES6 syntax.

(samurai music)…- [Kyle] Here's the non-recursive…way to sum up three numbers.…We're going to loop over the list of them.…Have a running sum, starts with zero.…Just add them together, I end up with 12 at the end.…Pretty straight forward.…How can we express this same program recursively?…Well this isn't as pretty as recursive…functions usually look,…and part of the reason for that…is that there's some JavaScript nonsense here,…like changing arguments into the args.…

That sort of thing; that's kind of ugly.…But, I promise on the very next slide…I'm about to show you a prettier way of expressing it,…now that we have ES6.…But, importantly here, we have a base case.…Our if statement is a base case,…in which case we return an immediate operation…that doesn't need to call any other function.…And then we have a recursive call.…So we have our two characteristics…that make this a recursive solution.…And you'll notice that what I'm saying here…is that the summation of any list of numbers…is the same thing as the first number plus…

Resume Transcript Auto-Scroll

Author

Released

5/12/2017

In this course, Kyle Simpson covers key aspects of functional programming to help you enhance your JavaScript skills. Throughout the course, Kyle covers concepts in a practical manner, skipping the obscure language that's sometimes used to talk about simple concepts. He covers topics such as pure functions, composability and immutability, closure, and recursion. When you wrap up this course, you'll have the tools you need to start improving your programs today.

This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.