Exercise 7 · Chapter: Closures & IteratorsRequired+50 XP
Fold Product
Use .fold() to calculate the product of all numbers in vec![2, 3, 4]. Start with 1 as the initial value.
Expected output:
Product: 24
Hints:
.fold(1, |acc, x| acc * x)starts with 1 and multiplies each itemaccis the accumulator (running total),xis the current item
rust
fn main() {
}
Output
Run your code to see the output here.