roman: refactor to use string building pattern
This commit is contained in:
parent
3a0808c599
commit
2515644d4f
@ -4,13 +4,12 @@ import "strings"
|
||||
|
||||
func ConvertToRoman(arabic int) string {
|
||||
var converted strings.Builder
|
||||
if arabic <= 3 {
|
||||
for i := 0; i < arabic; i++ {
|
||||
converted.WriteString("I")
|
||||
for i := arabic; i > 0; i-- {
|
||||
if i == 4 {
|
||||
converted.WriteString("IV")
|
||||
break
|
||||
}
|
||||
}
|
||||
if arabic == 4 {
|
||||
return "IV"
|
||||
converted.WriteString("I")
|
||||
}
|
||||
return converted.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user