So far in this chapter, we have been moving in the direction of outputting more and more information from the server into HTML so that our client-side scripts can remain as lean and efficient as possible. Now let's consider a different scenario, one in which a whole new set of information is displayed when JavaScript is available. Increasingly, web applications rely on JavaScript to deliver content as well as manipulate it once it arrives. In our third table sorting example, we'll do the same.
We'll start by writing three functions:
- buildAuthors(): This builds a string list of author names
- buildRow(): This builds the HTML for a single table row
- buildRows(): This builds the HTML for the entire table by mapping the rows built by buildRow()
const buildAuthors = row =>
row
.authors
.map(a => `${a.first_name} ${a.last_name}`)
.join('...