Reduce transform stream which computes the quantiles over a stream of numeric data.
Note: in order to calculate the quantiles exactly, all data must be buffered into memory. As a result, this stream acts as a sink. Use caution when applying the transform to large datasets.
$ npm install flow-quantilesvareventStream=require('event-stream'),qStream=require('flow-quantiles');// Create some data...vardata=newArray(1000);for(vari=0;i<data.length;i++){data[i]=Math.round(Math.random()*100);}// Create a readable stream:varreadStream=eventStream.readArray(data);// Create a new quantiles stream:varstream=qStream().quantiles(10).stream();// Pipe the data:readStream.pipe(stream).pipe(eventStream.stringify()).pipe(process.stdout);Unit tests use the Mocha test framework with Chai assertions.
Assuming you have installed Mocha, execute the following command in the top-level application directory to run the tests:
$ mochaAll new feature development should have corresponding unit tests to validate correct functionality.
Copyright © 2014. Athan Reines.