- cross-posted to:
- learningrustandlemmy
- cross-posted to:
- learningrustandlemmy
Going through some exercises on basic Rust syntax and ownership.
Links:
- Exercises: https://101-rs.tweede.golf/A1-language-basics/mod.html
- Slides: http://artificialworlds.net/presentations/rust-101/A1-intro-to-rust
Rust 101 is a series of videos explaining how to write programs in Rust. The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.
This series of videos is copyright 2023 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.
Heya Andy!
Thoughts on using or not using
.sort()
in exercise1-basic-syntax/03.rs
rather than rolling your own code for determining minimum and maximum values??For me, I just (lazily) landed on:
fn main() { let mut input = [23, 82, 16, 45, 21, 94, 12, 34]; // TODO input.sort(); let (smallest, largest) = (input[0], input[input.len()-1]); println!("{largest} is largest and {smallest} is smallest"); }
@maegul@lemmy.ml using
sort
looks like a nice solution. For very large lists it will be doing more work than is strictly necessary, but for most use cases that would be great, and nice and simple.Thanks! Yea I’m clearly taking the easy route there with sort.
Though it did make wonder why there’s no max or min methods even though there’s a sort … question for another time perhaps 🤔