Skip to content

Instantly share code, notes, and snippets.

@neocotic
neocotic / average-sampler.js
Last active April 27, 2022 11:19
Average Sampler
/**
* Generates sample data based on the `options` provided and then calculates the average based on the sample count.
*
* @param {Object} options - The options to be used.
* @param {function(): *} options.generator - The function to be used to generate data per round.
* @param {number} [options.roundsPerSample=1000] - The number of rounds in which `options.generator` is to be called per sampling.
* @param {function(value: *): boolean} options.sampler - The function to be used to filter samples from the generated data.
* @param {number} [options.samples=100] - The number of times samples should be run.
* @return {number} The calculated average.
*/