What does this print?
let nums = [2, 3, 4]
let product = nums.reduce(1) {
$0 * $1
}
print(product)
let sum = nums.reduce(0, +)
print(sum)
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
24 9
Explanation:
reduce combines elements using an accumulator and closure.
[/spoiler]