JS1K

#2: the original

Source for demo by Trevor Norris. See also description.

(function(l,j){var o={},b="sum",r="min",t="max",u="mean",h="median",p="range",g="variance",m="stdev",k="quartiles",e="covariance",s="corrcoeff",c=l.min,f=l.max,a=l.floor,q=l.pow,n=l.sqrt,d=l.round,i=function(w,v){return w-v};o[b]=function(v){var x=0,w=v.length-1;for(;w>=0;w--){x+=v[w]}return x};o[r]=function(v){return c.apply(l,v)};o[t]=function(v){return f.apply(l,v)};o[u]=function(v){return o[b](v)/v.length};o[h]=function(v){var x=v.length,w=v.slice(0).sort(i);return !(x&1)?(w[(x/2)-1]+w[(x/2)])/2:w[a(x/2)]};o[p]=function(v){var w=v.slice(0).sort(i);return w[w.length-1]-w[0]};o[g]=function(v){var z=o[u](v),w=0,x=v.length,y=x;for(x--;x>=0;x--){w+=q((v[x]-z),2)}return w/(y-1)};o[m]=function(v){return n(o[g](v))};o[k]=function(v){var x=v.length,w=v.slice(0).sort(i);return[w[d((x)/4)-1],w[d((x)/2)-1],w[d((x)*3/4)-1]]};o[e]=function(A,y){var z=o[u](A),x=o[u](y),C=[],w=A.length,B=0;for(;B<w;B++){C[B]=(A[B]-z)*(y[B]-x)}return o[b](C)/w};o[s]=function(w,v){return o[e](w,v)/o[m](w)/o[m](v)};j.jStat=o})(Math,window);