mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-30 00:51:47 +00:00
8 lines
238 B
TypeScript
8 lines
238 B
TypeScript
export const median = (arr: number[]) => {
|
|
const mid = Math.floor(arr.length / 2);
|
|
const nums = [...arr].sort((a, b) => a - b);
|
|
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
|
};
|
|
|
|
export default median;
|