Files
compiler-explorer/examples/swift/Sum_over_array.swift
2017-10-16 10:37:03 +02:00

14 lines
302 B
Swift

// Imperative style sum over an array of integers
func imperativeSum(input: [Int]) -> Int {
var sum = 0
for value in input {
sum += value
}
return sum
}
// Functional style sum over an array of integers
func functionalSum(input: [Int]) -> Int {
return input.reduce(0, +)
}