mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
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.
10 lines
299 B
TypeScript
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];
|
|
}
|
|
};
|