Here's the start of an implementation:
/* http://www.nist.gov/dads/HTML/mean.html */
var mean = function() {
var data = flattenArguments(arguments);
return sum(data) / data.length;
};
/* http://www.nist.gov/dads/HTML/median.html */
var median = function() {
var data = flattenArguments(arguments);
data.sort(compare);
if (data.length % 2 == 0) {
var upper = data.length / 2;
return (data[upper] + data[upper - 1]) / 2;
} else {
return data[(data.length - 1) / 2];
}
};
They need to be optimized a bit, and should return NaN when passed no arguments or an empty list. Need to inline sum() to kill the Iter dependency. They should live in Base along with listMin and listMax. While we're at it, listMin and listMax should probably return the same values as Math.min() and Math.max().
http://groups.google.com/group/mochikit/browse_thread/thread/32378e01109df541