mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
14 lines
302 B
Swift
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, +)
|
|
}
|