2024-09-10 11:20:33 +00:00
|
|
|
package iteration
|
|
|
|
|
2024-09-10 11:39:14 +00:00
|
|
|
import "strings"
|
|
|
|
|
2024-09-10 11:20:33 +00:00
|
|
|
// Repeat takes a string and repeat it 5 times
|
2024-09-10 11:32:46 +00:00
|
|
|
func Repeat(s string, repeatTime int) string {
|
2024-09-10 11:39:14 +00:00
|
|
|
// // Bench: 170ns
|
|
|
|
// var res string
|
|
|
|
// for i := 0; i < repeatTime; i++ {
|
|
|
|
// res += s
|
|
|
|
// }
|
|
|
|
// return res
|
|
|
|
|
|
|
|
// Bench: 70ns
|
|
|
|
return strings.Repeat(s, repeatTime)
|
2024-09-10 11:20:33 +00:00
|
|
|
}
|