diff options
| author | mo khan <mo.khan@gmail.com> | 2019-10-23 20:11:29 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-10-23 20:11:29 -0600 |
| commit | d87ddbb288b7407179285c0f5193b3272027eea6 (patch) | |
| tree | c659940475e3954252b66fad31aec1c153e7aa37 | |
| parent | da86ef8bd27327bf019e65751a827744e3a46a6e (diff) | |
Add times parameter
| -rw-r--r-- | repeat.go | 4 | ||||
| -rw-r--r-- | repeat_test.go | 4 |
2 files changed, 4 insertions, 4 deletions
@@ -1,8 +1,8 @@ package main -func Repeat(character string) string { +func Repeat(character string, times int) string { var repeated string - for i := 0; i < 5; i++ { + for i := 0; i < times; i++ { repeated += character } return repeated diff --git a/repeat_test.go b/repeat_test.go index 4cfe358..ccb8d12 100644 --- a/repeat_test.go +++ b/repeat_test.go @@ -4,7 +4,7 @@ import "testing" func TestRepeat(t *testing.T) { t.Run("default", func(t *testing.T) { - repeated := Repeat("a") + repeated := Repeat("a", 5) expected := "aaaaa" if repeated != expected { @@ -24,6 +24,6 @@ func TestRepeat(t *testing.T) { func BenchmarkRepeat(b *testing.B) { for i := 0; i < b.N; i++ { - Repeat("a") + Repeat("a", 5) } } |
