what about more interesting calculations that don' come bundled with crossfiltersuch as an averagefor instanceyou can still do that but you' need to write three functions and feed them to reduce(method let' say you want to know the average stock per medicine as previously mentionedalmost all of the mapreduce logic needs to be written by you an average is nothing more than the division of sum by countso you will require bothhow do you go about thisapart from the reducecount(and reducesum(functionscrossfilter has the more general reduce(function this function takes three argumentsthe reduceadd(function-- function that describes what happens when an extra observation is added the reduceremove(function-- function that describes what needs to happen when an observation disappears (for instancebecause filter is appliedthe reduceinit(function--this one sets the initial values for everything that' calculated for sum and count the most logical starting point is let' look at the individual reduce functions you'll require before trying to call the crossfilter reduce(methodwhich takes these three components as arguments custom reduce function requires three componentsan initiationan add functionand remove function the initial reduce function will set starting values of the objectvar reduceinitavg function( , )return {count stocksum stockavg: }as you can seethe reduce functions themselves take two arguments these are automatically fed to them by the crossfilter reduce(methodp is an object that contains the combination situation so farit persists over all observations this variable keeps track of the sum and count for you and thus represents your goalyour end result represents record of the input data and has all its variables available to you contrary to pit doesn' persist but is replaced by new line of data every time the function is called the reduceinit(is called only oncebut reduceadd(is called every time record is added and reduceremove(every time line of data is removed the reduceinit(functionhere called reduceinitavg(because you're going to calculate an averagebasically initializes the object by defining its components (countsumand averageand setting their initial values let' look at reduceaddavg()var reduceaddavg function( , ) count + stocksum stocksum number( stock) stockavg math round( stocksum count)return