Files
faunosteo/scripts/browser/lib/stats.mjs
T
bchanot 4439fd2420 test(tests): R4.1e browser harness and TS baselines (Chromium, Firefox, WebKit)
Playwright harness under scripts/browser: 127.0.0.1 server with the DEPLOY
CSP, export and import baselines of the TypeScript engine under a 4 GiB RSS
watchdog (not a guaranteed memory limit), O9 browser columns in
inflate.browsers.json (26 rows agree with Node in all three engines).
Results of 2026-10-18 committed; the O9 Node test no longer expects browser
columns in inflate.json.
2026-10-18 15:05:28 +02:00

22 lines
742 B
JavaScript

/** Small descriptive statistics for the summary tables. */
const sorted = (values) => [...values].sort((a, b) => a - b)
export function median(values) {
const list = sorted(values)
if (list.length === 0) return null
const mid = Math.floor(list.length / 2)
return list.length % 2 ? list[mid] : (list[mid - 1] + list[mid]) / 2
}
/** Median and range of the finite numbers of `values` (nulls skipped). */
export function spread(values) {
const list = sorted(values.filter((v) => Number.isFinite(v)))
if (list.length === 0) return null
const min = list[0]
const max = list[list.length - 1]
return { n: list.length, median: median(list), min, max }
}
export const sum = (values) => values.reduce((total, v) => total + v, 0)