-
Book Overview & Buying
-
Table Of Contents
Learning UnderscoreJS
By :
We dealt so far with functions tasked with extracting a value or a range of values from collections, and we will now move to functions that aggregate or transform collections. Aggregate functions operate over an entire collection to extract or calculate a single value or a limited set of values. Transformation functions operate over an entire collection and return a new collection that is usually a different representation of the original collection.
The first example of an aggregate function was _.reduce() and the first example of a transformation function was _.map(). The former calculates an accumulator value from the entire collection and the latter creates a new collection from the original collection.
We will use our example data for this chapter to revisit _.reduce() and define a new requirement to calculate the average rental price for all bicycles or for bicycles of a specific type. We will implement the getAverageRentalPrice(type) function...
Change the font size
Change margin width
Change background colour