Tsallaka zuwa abun ciki
Justice Tech School

Practice: Stats

Compute min, max and average with iterators.

Example
fn main() {
    let v = [4.0, 8.0, 6.0];
    let sum: f64 = v.iter().sum();
    let max = v.iter().cloned().fold(f64::MIN, f64::max);
    println!("{} {} {:.2}", sum, max, sum / v.len() as f64);
}

Result

18 8 6.00

Exercise

Average.

sum / v.len()  f64

Quiz Test

Why cast len?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.