pub fn percentile<T>(collection: &[T], p: f64) -> Option<f64>Expand description
Calculates the specified percentile of a collection. The percentile should be a value between 0 and 100. The collection will be sorted before calculation. Uses linear interpolation between closest ranks for non-integer results.
§Arguments
collection- A slice of items to calculate the percentile fromp- The percentile to calculate (0-100)
§Returns
Option<f64>- The calculated percentile value, or None if the collection is empty
§Examples
use lowdash::percentile;
let numbers = vec![1, 2, 3, 4, 5];
let result = percentile(&numbers, 50.0);
assert!((result.unwrap() - 3.0).abs() < f64::EPSILON);use lowdash::percentile;
let numbers = vec![1, 2, 3, 4];
let result = percentile(&numbers, 75.0);
assert!((result.unwrap() - 3.25).abs() < f64::EPSILON);