mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
15 lines
418 B
Swift
15 lines
418 B
Swift
// Imperative style array of maximum values per index
|
|
func imperativeMaxArray(x: [Int], y: [Int]) -> [Int] {
|
|
var maxima: [Int] = []
|
|
let count = min(x.count, y.count)
|
|
for index in 0..<count {
|
|
maxima.append(max(x[index], y[index]))
|
|
}
|
|
return maxima
|
|
}
|
|
|
|
// Functional style array of maximum values per index
|
|
func functionalMaxArray(x: [Int], y: [Int]) -> [Int] {
|
|
return zip(x, y).map(max)
|
|
}
|