Split RepeatFive, handle counts, add examples
This commit is contained in:
@@ -2,11 +2,18 @@ package iteration
|
||||
|
||||
import "strings"
|
||||
|
||||
const repeatCount = 5
|
||||
const defaultRepeatCount = 5
|
||||
|
||||
func Repeat(character string) string {
|
||||
func RepeatFive(character string) string {
|
||||
return Repeat(character, defaultRepeatCount)
|
||||
}
|
||||
|
||||
func Repeat(character string, count int) string {
|
||||
if count == 0 {
|
||||
count = defaultRepeatCount
|
||||
}
|
||||
var repeated strings.Builder
|
||||
for range repeatCount {
|
||||
for range count {
|
||||
repeated.WriteString(character)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user