swiftlyfox/SwiftyFox.playground/Contents.swift
Tony Bark 82077a9bb2 Added ArgumentParser to main project
- At Swift book's Functions and Closure section in Playgrounds (next up Objects and Classes)
2025-11-12 18:52:42 -05:00

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