mirror of
https://git.tonybark.com/tonytins/swiftlyfox.git
synced 2026-02-10 08:14:48 -05:00
- At Swift book's Functions and Closure section in Playgrounds (next up Objects and Classes)
28 lines
610 B
Swift
28 lines
610 B
Swift
import Cocoa
|
|
|
|
func greet(_ person: String, on day: String) -> String {
|
|
return "Hello \(person), today is \(day)."
|
|
}
|
|
|
|
// "Hello Tony Bark, today is Tuesday."
|
|
greet("Tony Bark", on: "Tuesday")
|
|
|
|
func calcStats(scores: [Int]) -> (min: Int, max: Int, sum: Int) {
|
|
var min = scores[0]
|
|
var max = scores[0]
|
|
var sum = 0
|
|
|
|
for score in scores {
|
|
if score > max {
|
|
max = score
|
|
} else if score < min {
|
|
min = score
|
|
}
|
|
sum += score
|
|
}
|
|
|
|
return (min, max, sum)
|
|
}
|
|
|
|
let stats = calcStats(scores: [5, 3, 100, 3, 9])
|
|
let sum = stats.sum // 120
|