Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Traversing a tree structure

Data structures, which include recursion in their definition, are naturally appropriate for recursive techniques. Let's consider here, for example, how to traverse a complete file system directory, listing all of its contents. Where's the recursion? The answer follows if you consider that each directory can do either of the following:

  • Be empty -- a base case, in which there's nothing to do
  • Include one or more entries, each of which is either a file or a directory itself

Let's work out a full recursive directory listing -- meaning, when we encounter a directory, we proceed to also list its contents and, if those include more directories, we also list them, and so on. We'll be using the same Node.js functions as ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content