MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / percentile

Function percentile

src/utils/mathUtils.ts:12–19  ·  view source on GitHub ↗
(sorted: number[], p: number)

Source from the content-addressed store, hash-verified

10 * @returns The p-th percentile value, or 0 if array is empty
11 */
12export function percentile(sorted: number[], p: number): number {
13 if (sorted.length === 0) return 0;
14 const idx = (p / 100) * (sorted.length - 1);
15 const lower = Math.floor(idx);
16 const upper = Math.ceil(idx);
17 if (lower === upper) return sorted[lower];
18 return sorted[lower] * (upper - idx) + sorted[upper] * (idx - lower);
19}
20
21/**
22 * Calculate the median of an array.

Callers 3

mathUtils.test.tsFile · 0.90
medianFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected