Skip to content

Commit 8b2f441

Browse files
committed
Use an Iterator approach in print_formatted
1 parent 244006c commit 8b2f441

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/main.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ fn main() -> Result<(), std::io::Error> {
1919
Ok(())
2020
}
2121

22-
fn print_formatted(v: &[weather::Station]) {
23-
print!("{{");
24-
for (i, record) in v.iter().enumerate() {
25-
if i < v.len() - 1 {
26-
print!("{record}, ");
27-
} else {
28-
print!("{record}");
29-
}
30-
}
31-
println!("}}")
22+
fn print_formatted(stations: &[weather::Station]) {
23+
let s = stations.iter().map(|st| st.to_string()).collect::<Vec<String>>().join(", ");
24+
println!("{{{s}}}");
3225
}

0 commit comments

Comments
 (0)