The array methods that return a new array, such as map, filter, reduce, and sort, can be chained together.
Let's start with the example data below. An array of objects that contain information about the distance between two cities. The distance is expressed in kilometers.
This solution looks nice, but there's actually a problem that you should be aware of. Each method, filter, map, and reduce, perform their own for loop to iterate through the elements in the array and call the function we supply.
That means there are three iterations through the array, compared to just one in our own for loop implementation.
This isn't a big deal in our very small sample size, but imagine you have a billion elements in the array. In that case you need to consider the performance implications of using this technique.