a reduce function that calculates mean and standard deviation in one pass
I first wrote this module a long long time ago, and i used an object oriented api. Today I needed to serialize a stats output to JSON, and then later parse it, and keep using it. Continuing to use an OO api would mean a bunch of glue code, so I rewrote it as a reduce function.
var stats =consolemean: 2stdev: 08164965809277263count: 3sum: 6sqsum: 14
you probably only want to have the mean and stdev, the other fields are necessary for the reduce function however.
sometimes, a mutating reduce is prefured. this eases garbage collection, and allows you to maintain a reference to an updating value.
otherwise the api is the same.
statistics@2 and earlier used an object oriented api, but then I needed to serialize and parse a stats object and keep using it. That was incredibly easy with a reduce function, but would have meant a bunch of ugly glue code with OO.