From 539fc995fd701436ab3db3f385b56cb25fe082c0 Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 11 Jul 2019 12:32:50 +0000 Subject: [PATCH] Refactor go/twelve-days --- go/twelve-days/twelve-days.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go/twelve-days/twelve-days.go b/go/twelve-days/twelve-days.go index 8f6e43d..b4e9bb4 100644 --- a/go/twelve-days/twelve-days.go +++ b/go/twelve-days/twelve-days.go @@ -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 { + if day < 0 || day > 12 { + return "" + } return fmt.Sprintf( "On the %s day of Christmas my true love gave to me: %s.", 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) { for day := 1; day <= 12; day++ { song += fmt.Sprintf("%s\n", Verse(day))