SolarEnergy/central_backend/src/utils/math_utils.rs

9 lines
189 B
Rust
Raw Normal View History

2024-09-26 21:05:10 +00:00
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]
}