Chapter 5, Programming Declaratively – a Better Style

5.1. Filtering... but what? Boolean(x) is the same as !!x, and it turns an expression from being truthy or falsy into true or false, respectively. Thus, the .filter() operation removes all falsy elements from the array.

5.2. Generating HTML code, with restrictions: In real life, you wouldn't limit yourself to using only filter(), map(), and reduce(), but the objective of this question was to make you think about how to manage with only those. Using join() or other extra string functions would make the problem easier. For instance, finding out a way to add the enclosing <div><ul> ... </ul></div> tags is tricky, so we had to make the first reduce() operation produce an array so that we could ...

Get Mastering JavaScript Functional Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.