Added ArgumentParser to main project

- At Swift book's Functions and Closure section in Playgrounds (next up Objects and Classes)
This commit is contained in:
Tony Bark 2025-11-12 18:52:42 -05:00
parent 8f83d25989
commit 82077a9bb2
4 changed files with 49 additions and 21 deletions

View file

@ -1,22 +1,28 @@
import Cocoa
let interestingNumbers = [
"Prime": [2, 3, 5, 7, 11, 13],
"Fibonacci": [1, 1, 2, 3, 5, 8],
"Square": [1, 4, 9, 16, 25],
];
func greet(_ person: String, on day: String) -> String {
return "Hello \(person), today is \(day)."
}
var largest = 0
// "Hello Tony Bark, today is Tuesday."
greet("Tony Bark", on: "Tuesday")
for (_, numbers) in interestingNumbers {
for number in numbers {
if number > largest {
largest = number // 25
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)
}
var total = 0
for i in 0..<4 {
total += i // 6
}
let stats = calcStats(scores: [5, 3, 100, 3, 9])
let sum = stats.sum // 120