Learn how the Lodash functions map, reduce, filter, every, and some can be combined to perform a wide variety of calculations on a set of data. We use the example of calculating the average ages of all male and female employees from a simple data set.
- [Instructor] We've seen that the functions…map, filter, and reduce can be very useful on their own.…But combining these functions…can make them even more useful.…Let's go through an example to see how.…Imagine that we have an array of employee data.…We want to find out how the average age of males…compares with that of females.…By chaining the map, filter, and reduce functions together…we can neatly perform this calculation.…The first thing we'll do is filter our array…so that we end up with an array of only the male employees.…
To do this we call filter with a function…that checks if each employee is male…and returns true if they are.…This will give us an array of all the male employees…from our original array.…We then want to convert this array of male employees…into an array of the ages of the male employees.…To do this we use map with a function that takes…a male employee object and changes it into a number…representing his age.…
Now that we have the ages of all the male employees…we want to find out what the total is…
- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments