pub fn median(nums: &[f64]) -> Option<f64> {
    // Make a sorted copy of the input floats.
    let mut nums = nums.to_owned();
    // https://users.rust-lang.org/t/how-to-sort-a-vec-of-floats/2838/2
    nums.sort_by(|a, b| a.partial_cmp(b).unwrap());

    if nums.is_empty() {
        None
    } else {
        let mid = (nums.len() - 1) / 2;
        Some(nums[mid])
    }
}
/// Median value of input values, taking the value closer
/// to the beginning to break ties. The median
/// of an empty list is undefined.
///
/// # Examples:
///
/// ```
/// # use stats::*;
/// assert_eq!(None, median(&[]));
/// ```
/// ```
/// # use stats::*;
/// assert_eq!(Some(0.0), median(&[0.0, 0.5, -1.0, 1.0]));
/// ```
/// ```
/// # use stats::*;
/// assert_eq!(Some(5.0), median(&[5.0]));
/// ```
Median value of input values, taking the value closer
to the beginning to break ties. The median
of an empty list is undefined.
Median value of input values taking the value closer to the beginning to break ties . The median of an empty list is undefined .
pub fn median(nums: &[f64]) -> Option<f64> {
    // Make a sorted copy of the input floats.
    let mut nums = nums.to_owned();
    // https://users.rust-lang.org/t/how-to-sort-a-vec-of-floats/2838/2
    nums.sort_by(|a, b| a.partial_cmp(b).unwrap());
    if nums.is_empty() {
        None
    } else {
        let mid = (nums.len() - 1) / 2;
        Some(nums[mid])
    }
}
pub fn median ( nums : & [ f64 ] ) -> Option < f64 > { // Make a sorted copy of the input floats. let mut nums = nums . to_owned ( ) ; // https://users.rust-lang.org/t/how-to-sort-a-vec-of-floats/2838/2 nums . sort_by ( | a , b | a . partial_cmp ( b ) . unwrap ( ) ) ; if nums . is_empty ( ) { None } else { let mid = ( nums . len ( ) - 1 ) / 2 ; Some ( nums [ mid ] ) } }
Median value of input values, taking the value closer
to the beginning to break ties.
Median value of input values taking the value closer to the beginning to break ties .
nums
&[f64]
nums
&[f64]
examples:
None
use stats::*;
None
use stats::*;
None
use stats::*;
None