Making sense of reduce()

- [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,…

Resume Transcript Auto-Scroll

Author

Released

1/9/2017

Need to slice and dice large and complex JavaScript data arrays with maximum speed and effectiveness? Enter Crossfilter.js. An alternative to expensive tools like Qlikview, Crossfilter manages the data that lie behind charts, allowing data scientists to group and filter data quickly and easily, right in the browser. Join Emma Saunders in this entry- through intermediate-level course, which explores data indexing and filtering with Crossfilter. Learn how to download and set up Crossfilter, create and use dimensions (which function similarly to properties) to filter data, group and reduce results, set up advanced filters to sort by range or function, and perform actions (like removals) on matching records.