SolarEnergy/central_backend/src/utils/math_utils.rs
2024-09-26 23:05:10 +02:00

9 lines
189 B
Rust

use std::ops::Div;
pub fn median<E: Div + Copy + Ord>(numbers: &[E]) -> E {
let mut numbers = numbers.to_vec();
numbers.sort();
let mid = numbers.len() / 2;
numbers[mid]
}