Refactor go/twelve-days

This commit is contained in:
dwrz
2019-07-11 12:34:33 +00:00
parent bfe7491f4c
commit 539fc995fd
+7
View File
@@ -56,7 +56,12 @@ func giftsForDay(day int) string {
} }
} }
// Verse returns the matching verse for the inputted day.
// Day must be an integer between 1 and 12.
func Verse(day int) string { func Verse(day int) string {
if day < 0 || day > 12 {
return ""
}
return fmt.Sprintf( return fmt.Sprintf(
"On the %s day of Christmas my true love gave to me: %s.", "On the %s day of Christmas my true love gave to me: %s.",
ordinals[day], ordinals[day],
@@ -64,6 +69,8 @@ func Verse(day int) string {
) )
} }
// Song returns the text of the song "Twelve Days of Christmas".
// Its verses are separated by newlines.
func Song() (song string) { func Song() (song string) {
for day := 1; day <= 12; day++ { for day := 1; day <= 12; day++ {
song += fmt.Sprintf("%s\n", Verse(day)) song += fmt.Sprintf("%s\n", Verse(day))