diff options
author | Rubén <rubrinbla@gmail.com> | 2017-10-16 10:37:03 +0200 |
---|---|---|
committer | Rubén <rubrinbla@gmail.com> | 2017-10-16 10:37:03 +0200 |
commit | 85a392fdcffc52f69d74d7746a318e49b68f664b (patch) | |
tree | 3cd964a4bb8eb0a117e11602128c27165196c10e /examples/swift/Max_array.swift | |
parent | c6838692f73b41b21a5adecec85c3213b9628e99 (diff) | |
download | compiler-explorer-85a392fdcffc52f69d74d7746a318e49b68f664b.tar.gz compiler-explorer-85a392fdcffc52f69d74d7746a318e49b68f664b.zip |
Split libs in columns of 5
Diffstat (limited to 'examples/swift/Max_array.swift')
-rw-r--r-- | examples/swift/Max_array.swift | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/examples/swift/Max_array.swift b/examples/swift/Max_array.swift new file mode 100644 index 000000000..887778736 --- /dev/null +++ b/examples/swift/Max_array.swift @@ -0,0 +1,14 @@ +// 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) +} |