perf: Use string builder
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package iteration
|
||||
|
||||
import "strings"
|
||||
|
||||
const repeatCount = 5
|
||||
|
||||
func Repeat(character string) string {
|
||||
var repeated string
|
||||
var repeated strings.Builder
|
||||
for range repeatCount {
|
||||
repeated = repeated + character
|
||||
repeated.WriteString(character)
|
||||
}
|
||||
|
||||
return repeated
|
||||
return repeated.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user