December 2018
Intermediate to advanced
642 pages
15h 5m
English
A second type of very common operation is to go through an array and produce a new array by doing some kind of process to each element. Fortunately, we also have a way to do that functionally by using .map(). The way this function works is simple: given an array and a function, it applies the function to each element of the array and produces a new array with the results of each call.
Suppose we called a web service and got back an array with people data. We just wanted their ages so that we are able to do some other process; say, calculate the average age of the people who used the service. We can manage this simply:
// Source file: src/map_filter_reduce.jstype person = { name: string, sex: string, age: number };const family: ...Read now
Unlock full access