Exerpad
🔥 0
0 XP
Exercise 3 · Chapter: Closures & IteratorsRequired+50 XP

Map Doubles

Use .iter() and .map() to double every number in vec![1, 2, 3, 4, 5]. Collect the results into a new Vec<i32> and print it.

Expected output:

[2, 4, 6, 8, 10]

Hints:

  • Use .iter().map(|x| x * 2).collect()
  • You need a type annotation: let doubled: Vec<i32> = ...
  • Print with {:?}
rust
fn main() {
}
Output
Run your code to see the output here.