March 2019
Intermediate to advanced
208 pages
5h 11m
English
As we saw at the beginning of this chapter, the default display of a list leaves much to be desired. If we have a list with more than three elements, we see only the first three and then the word Array (which is odd, given that we have a list rather than array) or Object to indicate that there are more elements. While writing this chapter, though, I needed to see all the elements, so I wrote a function named stringOfList to get things done.
The general plan was to use reduce: the accumulator starts off as the empty string. The reducer function converts a list element to a string and appends it, along with a comma and space, to the accumulator. Here’s the code for a list of integers:
Read now
Unlock full access