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 {
|
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("IV")
|
||||||
|
break
|
||||||
|
}
|
||||||
converted.WriteString("I")
|
converted.WriteString("I")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if arabic == 4 {
|
|
||||||
return "IV"
|
|
||||||
}
|
|
||||||
return converted.String()
|
return converted.String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user