Claus Witt dot com

webdeveloper

I love tinkering with javascript, and working out solutions to simple little problems. Recently I had a simple statistical program in mind, that should be able to run in the browser. However while thinking about the idea, I wondered if there were any statistical functions in js allready available. Most like for instance jStat were completely overkill. I just needed mean, harmonic mean, geometric mean, standard deviation and median for a simple array of values.

I decided to write up a simple little "class" for that myself.

The code should pretty much speak for itself, and all functions have a comment with a link to the description of what it is on Wikipedia.

The complete source of the Stats.js file is embedded here. (Or go to gist.github.com to fork it).

The package can be used like so:

var stat = Stats([12, 13, 15, 18, 19, 4, 59, 100, 6, 129, 83, 5]);
console.log(stat.getArithmeticMean()); //38.583333333333336
console.log(stat.getGeometricMean()); //20.66546833393584
console.log(stat.getHarmonicMean()); //12.017712168189883
console.log(stat.getStandardDeviation()); //41.27844137346058
console.log(stat.getMedian()); //18
blog comments powered by Disqus