this repo has no description

:sparkles: (Go) Repeat function received times to repeat char

Changed files
+10 -10
Go
+2 -4
Go/iteration/repeat.go
··· 1 1 package iteration 2 2 3 - const repeatedCount = 5 4 - 5 - func Repeat(char string) string { 3 + func Repeat(char string, numberTimes int) string { 6 4 var repeated string 7 5 8 - for i := 0; i < repeatedCount; i++ { 6 + for i := 0; i < numberTimes; i++ { 9 7 repeated += char 10 8 } 11 9
+8 -6
Go/iteration/repeat_test.go
··· 3 3 import "testing" 4 4 5 5 func TestRepeat(t *testing.T) { 6 - repeated := Repeat("a") 7 - expected := "aaaaa" 6 + t.Run("should repeat the number of times passed to function", func(t *testing.T) { 7 + repeated := Repeat("a", 3) 8 + expected := "aaa" 8 9 9 - if repeated != expected { 10 - t.Errorf("expected %q but got %q", expected, repeated) 11 - } 10 + if repeated != expected { 11 + t.Errorf("expected %q but got %q", expected, repeated) 12 + } 13 + }) 12 14 } 13 15 14 16 func BenchmarkRepeat(b *testing.B) { 15 17 for i := 0; i < b.N; i++ { 16 - Repeat("a") 18 + Repeat("a", 5) 17 19 } 18 20 }