1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00
unleash.unleash/src/lib/util/median.ts
Jaanus Sellin 958ccabb54
feat: lifecycle prometheus metrics per project (#7032)
When we pushed metrics per feature, it had too many datapoints and
grafana could not handle it. Now I am taking median for a project.
2024-05-10 15:24:27 +03:00

10 lines
299 B
TypeScript

export const median = (numbers: number[]): number => {
numbers.sort((a, b) => a - b);
const midIndex = Math.floor(numbers.length / 2);
if (numbers.length % 2 === 0) {
return (numbers[midIndex - 1] + numbers[midIndex]) / 2;
} else {
return numbers[midIndex];
}
};