robosats/frontend/src/utils/match.ts

8 lines
232 B
TypeScript
Raw Normal View History

export const median = (arr: number[]) => {
const mid = Math.floor(arr.length / 2),
nums = [...arr].sort((a, b) => a - b);
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
};
2022-09-09 17:18:04 +00:00
export default median;