DEV Community

loading...

Discussion on: Challenge: Get Closest Number in an Array

Collapse
kip13 profile image
kip

Rust 🦀

numbers.iter().min_by_key(|&num| (num - given_num).abs()).unwrap()
Collapse
andy profile image
Andy Zhao (he/him) Author

Nice, didn't know Rust had similar syntax to Ruby!