Book Image

Mastering JavaScript Functional Programming

By : Federico Kereki
Book Image

Mastering JavaScript Functional Programming

By: Federico Kereki

Overview of this book

Functional programming is a programming paradigm for developing software using functions. Learning to use functional programming is a good way to write more concise code, with greater concurrency and performance. The JavaScript language is particularly suited to functional programming. This book provides comprehensive coverage of the major topics in functional programming with JavaScript to produce shorter, clearer, and testable programs. You’ll delve into functional programming; including writing and testing pure functions, reducing side-effects, and other features to make your applications functional in nature. Specifically, we’ll explore techniques to simplify coding, apply recursion for loopless coding, learn ways to achieve immutability, implement design patterns, and work with data types. By the end of this book, you’ll have developed the JavaScript skills you need to program functional applications with confidence.
Table of Contents (22 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback
Connecting Functions - Pipelining and Composition
Answers to Questions

Chapter 9. Designing Functions - Recursion

In Chapter 8, Connecting Functions - Pipelining And Composition, we considered yet more ways to create new functions out of combining previous existing ones. Here, we are going to get into a different theme: how to actually design and write functions, in a typically functional way, by applying recursive techniques.

We will be covering the following topics:

  • Understanding what recursion is and how to think in order to produce recursive solutions
  • Applying recursion to some well-known problems, such as making change or the Tower of Hanoi
  • Using recursion instead of iteration to re-implement some higher-order functions from earlier chapters
  • Writing search and backtrack algorithms with ease
  • Traversing data structures, such as trees, to work with file system directories or with the browser DOM
  • Getting around some limitations caused by browser JS engine considerations