Ad
Code
Diff
  • // lovely
    //hi
    //hi
    fn calc_gpa(grades: &str) -> f64 {
        let grade_points: Vec<f64> = grades
            .split_whitespace()
            .flat_map(str::parse)
            .map(|grade| match grade {
                90..=100 => 4.0,
                80..=89 => 3.0,
                70..=79 => 2.0,
                60..=69 => 1.0,
                _ => 0.0
            })
            .collect();
        
        grade_points.iter().sum::<f64>() / grade_points.len() as f64
    }
    • // lovely
    • //hi
    • //hi
    • fn calc_gpa(grades: &str) -> f64 {
    • let grade_points: Vec<f64> = grades
    • .split_whitespace()
    • .flat_map(str::parse)
    • .map(|grade| match grade {
    • 90..=100 => 4.0,
    • 80..=89 => 3.0,
    • 70..=79 => 2.0,
    • 60..=69 => 1.0,
    • _ => 0.0
    • })
    • .collect();
    • grade_points.iter().sum::<f64>() / grade_points.len() as f64
    • }