Calculates the median value from an array of numbers
Array of numbers to calculate median from
The median value
If array is empty
// Odd number of elementsconst numbers1 = [10.5, 2.3, 15.7];const median1 = median(numbers1); // Returns 10.5// Even number of elementsconst numbers2 = [2.3, 10.5, 15.7, 20.1];const median2 = median(numbers2); // Returns 13.1 ((10.5 + 15.7) / 2) Copy
// Odd number of elementsconst numbers1 = [10.5, 2.3, 15.7];const median1 = median(numbers1); // Returns 10.5// Even number of elementsconst numbers2 = [2.3, 10.5, 15.7, 20.1];const median2 = median(numbers2); // Returns 13.1 ((10.5 + 15.7) / 2)
Calculates the median value from an array of numbers