Files
Michał Pierzchała af6f12e391 chore: adopt shared oxlint config (#2115)
* chore: adopt shared oxlint config

* fix: preserve project lint boundaries

* fix: remove redundant oxlint config
2026-08-28 11:42:58 +02:00

23 lines
704 B
TypeScript

import type { Stat } from './types.ts';
// Nearest-rank percentile over a copy of the values.
function percentile(sorted: number[], p: number): number {
if (sorted.length === 0) return Number.NaN;
const rank = Math.ceil((p / 100) * sorted.length);
const idx = Math.min(sorted.length - 1, Math.max(0, rank - 1));
return sorted[idx];
}
export function summarize(values: number[]): Stat | null {
const clean = values.filter((v) => Number.isFinite(v));
if (clean.length === 0) return null;
const sorted = [...clean].sort((a, b) => a - b);
return {
n: sorted.length,
min: sorted[0],
median: percentile(sorted, 50),
p95: percentile(sorted, 95),
max: sorted.at(-1),
};
}