Chapter 5, Programming Declaratively – A Better Style
5.1 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 keep on working on it:
const characters = [ { name: "Fred", plays: "bowling" }, { name: "Barney", plays: "chess" }, { name: "Wilma", plays: "bridge" }, { name: "Betty", plays: "checkers" }, { name: "Pebbles", plays: "chess" }, ]; const list = characters ...