typedarray.p.[median() | lowerQuartile() | upperQuartile()]

in algorithmic trading, when setting across-the-board buy/sell prices for a basket of stocks (e.g sp500), its common to calculate a threshold price where 25% / 50% / 75% of stocks in basket will execute.

its not un-common to deal with gigabyte-scale typed-arrays in these scenarios, where performant median() / lowerQuartile() / upperQuartile() methods would be more ergonomic -- than having to implement them in custom node-addon or webassembly code.

The functions might work best like this:

Math.avg(1, 3, 5);
Math.median(1, 3, 5);

If Math.lowerQuartile and Math.upperQuartile are called serially, intermediate processing done by the first function must be redone by the second function. Would be nice to have a single function that returns both the lower and upper quartile.

Well, I suspect that these methods have a relatively lower chance to be included natively.

To me, the method should be named Math.mean (even if the word average is used, I definitely prefer the full form average to avg).

For quartile, a single method should be enough:

Math.quantile([1, 3, 5], 0.25); // 2
Math.quantile([1, 3, 5], [0, 0.25, 0.5, 0.75, 1]); // [1, 2, 3, 4, 5]

Someone may prefer naming it percentile, but at least Desmos named it quantile.

i ended up implementing kthpercentile(elem, percentile) in sqlite / c rather than javascript since majority of business-logic were sql-queries, and needed the speed-up in c for high-frequency-trading.

it still would be nice to have a [performant] quartile() / percentile() array-method in javascript though.