Skip to content

Instantly share code, notes, and snippets.

@barrault01
Last active December 22, 2020 15:51
Show Gist options
  • Save barrault01/15c5a9f55ea68080ff01fee6bf7094d6 to your computer and use it in GitHub Desktop.
Save barrault01/15c5a9f55ea68080ff01fee6bf7094d6 to your computer and use it in GitHub Desktop.
var alreadyGave = [String]()
let formatter = NumberFormatter()
formatter.numberStyle = .ordinal
[
"A partridge in a pear tree.",
"Two turtle doves",
"Three french hens",
"Four calling birds",
"Five gold rings",
"Six geese a-laying",
"Seven swans a-swimming",
"Eight maids a-milking",
"Nine ladies dancing",
"Ten lords a-leaping",
"Eleven pipers piping",
"Twelve drummers drumming"
].forEach {
alreadyGave.append($0.lowercased())
let dayOf = formatter.string(for: alreadyGave.count)!
print("On the \(dayOf) day of Christmas, my true love sent to me: ")
if alreadyGave.count > 1 {
print(alreadyGave
.reversed()
.dropLast()
.joined(separator: ", ") + " and " + alreadyGave.first!)
} else {
print($0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment