mirror of
https://github.com/rwinkhart/convertroman.git
synced 2026-08-29 05:16:26 -04:00
not using buffer to save b/op
This commit is contained in:
@@ -28,19 +28,27 @@ import (
|
||||
rom "github.com/brandenc40/romannumeral"
|
||||
)
|
||||
|
||||
func ExampleRomanToInt() {
|
||||
integer, err := rom.ToInt("IV")
|
||||
func ExampleStringToInt() {
|
||||
integer, err := rom.StringToInt("IV")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(integer == 4)
|
||||
fmt.Println(integer == 4) // True
|
||||
}
|
||||
|
||||
func ExampleIntToRoman() {
|
||||
roman, err := rom.FromInt(4)
|
||||
func ExampleBytesToInt() {
|
||||
integer, err := rom.BytesToInt([]byte("IV"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(roman == "IV")
|
||||
fmt.Println(integer == 4) // True
|
||||
}
|
||||
|
||||
func ExampleIntToString() {
|
||||
roman, err := rom.IntToString(4)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(roman == "IV") // True
|
||||
}
|
||||
```
|
||||
|
||||
+3
-3
@@ -53,14 +53,14 @@ func outOfBounds(input int) bool {
|
||||
}
|
||||
|
||||
func intToRoman(input int) []byte {
|
||||
output := bytes.Buffer{}
|
||||
var output []byte
|
||||
for _, rom := range _numerals {
|
||||
for input >= rom.val {
|
||||
output.Write(rom.sym)
|
||||
output = append(output, rom.sym...)
|
||||
input -= rom.val
|
||||
}
|
||||
}
|
||||
return output.Bytes()
|
||||
return output
|
||||
}
|
||||
|
||||
// StringToInt converts a roman numeral string to an integer. Roman numerals for numbers
|
||||
|
||||
Reference in New Issue
Block a user