iOS ● ● ○ Swift 6

Kodebits Day 84: Reduce Product

Aug 29 2026
Practice higher-order functions with a short swift challenge.

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]


Further Reading