diff --git a/Go/iteration/repeat.go b/Go/iteration/repeat.go new file mode 100644 index 0000000..c7b1de9 --- /dev/null +++ b/Go/iteration/repeat.go @@ -0,0 +1,13 @@ +package iteration + +const repeatedCount = 5 + +func Repeat(char string) string { + var repeated string + + for i := 0; i < repeatedCount; i++ { + repeated += char + } + + return repeated +} diff --git a/Go/iteration/repeat_test.go b/Go/iteration/repeat_test.go new file mode 100644 index 0000000..74e1ca6 --- /dev/null +++ b/Go/iteration/repeat_test.go @@ -0,0 +1,12 @@ +package iteration + +import "testing" + +func TestRepeat(t *testing.T) { + repeated := Repeat("a") + expected := "aaaaa" + + if repeated != expected { + t.Errorf("expected %q but got %q", expected, repeated) + } +}