roman: refactor to use string building pattern

This commit is contained in:
vinchent 2024-09-22 20:59:11 +02:00
parent 3a0808c599
commit 2515644d4f

View File

@ -4,13 +4,12 @@ import "strings"
func ConvertToRoman(arabic int) string { func ConvertToRoman(arabic int) string {
var converted strings.Builder var converted strings.Builder
if arabic <= 3 { for i := arabic; i > 0; i-- {
for i := 0; i < arabic; i++ { if i == 4 {
converted.WriteString("I") converted.WriteString("IV")
break
} }
} converted.WriteString("I")
if arabic == 4 {
return "IV"
} }
return converted.String() return converted.String()
} }