Learn how to use the reduce() function, including three sub-functions, and look inside them as they build a reduce method.
- [Instructor] Reduce, is the parent function…of Reduce sum, and Reduce count.…So, we could use Reduce to recreate either of these…two so-called convenience functions.…To use Reduce, we have to create three JavaScript functions,…one that decides when a row should be added,…one that decides when it should be removed,…and one that decides the initial value.…And I'm going to call these reduceAdd,…reduceRemove, and reduceInitial,…but you could call them anything you like.…
Between them, these three functions…define how we should distill our data.…And we can be quite flexible with them.…Now, we're going to start by declaring…the functions as they work, by default,…and then we'll modify them.…The default behavior, you might remember,…is to Reduce by count, so, basically, a row count.…So, reduceAdd takes two parameters, i and d,…i means initial, and d means data point, and we return i+1.…
reduceRemove takes i and d, as well, and we return i-1.…And then reduceInitial takes no parameters at all,…and it's typically set to 0, but, actually,…
Released
1/9/2017- Downloading Crossfilter
- Cross-filtering data
- Creating dimensions
- Grouping data
- Filtering by range and function
- Removing matching records
Share this video
Embed this video
Video: Making sense of reduce()