pub fn median<T>(collection: &[T]) -> Option<f64>Expand description
Calculate the median value of a collection. The median is the 50th percentile of a collection. For collections with an even number of elements, the median is the average of the two middle values. The collection will be sorted before calculation.
§Arguments
collection- A slice of items to calculate the median from
§Returns
Option<f64>- The median value, or None if the collection is empty
§Examples
use lowdash::median;
let numbers = vec![1, 3, 5, 2, 4];
let result = median(&numbers);
assert!((result.unwrap() - 3.0).abs() < f64::EPSILON);use lowdash::median;
let numbers = vec![1, 2, 3, 4];
let result = median(&numbers);
assert!((result.unwrap() - 2.5).abs() < f64::EPSILON);