exercism

Exercism solutions.
Log | Files | Refs

commit 539fc995fd701436ab3db3f385b56cb25fe082c0
parent bfe7491f4c5326bc6bba9380e0b424b2584284c0
Author: dwrz <dwrz@dwrz.net>
Date:   Thu, 11 Jul 2019 12:32:50 +0000

Refactor go/twelve-days

Diffstat:
Mgo/twelve-days/twelve-days.go | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git 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))