Sort a vector of floats

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    vector of f32 or f64

    fn main() {
      let mut vec = vec![1.1, 1.15, 5.5, 1.123, 2.0];
      vec.sort_by(|a, b| a.partial_cmp(b).unwrap());
      assert_eq!(vec, vec![1.1, 1.123, 1.15, 2.0, 5.5]);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.