let numbers = [1, 2, 3, 4, 5]↵
↵
let sum = numbers.reduce(0) { $0 + $1 }↵
let product = numbers.reduce(1, *)↵
↵
let words = ["Swift", "is", "awesome"]↵
let sentence = words.reduce("") { $0.isEmpty ? $1 : "\($0) \($1)" }↵
↵
let stats = numbers.reduce((min: Int.max, max: Int.min, sum: 0)) { result, num in↵
(min: min(result.min, num), max: max(result.max, num), sum: result.sum + num)↵
}↵
↵
print("Sum: \(sum), Product: \(product)")↵
print("Sentence: \(sentence)")↵
print("Stats: min=\(stats.min), max=\(stats.max), sum=\(stats.sum)")