Add iteration module

This commit is contained in:
2026-03-15 23:25:51 +01:00
parent 0ac0075904
commit cfab2d02a9
2 changed files with 34 additions and 0 deletions

12
iteration/iteration.go Normal file
View File

@@ -0,0 +1,12 @@
package iteration
const repeatCount = 5
func Repeat(character string) string {
var repeated string
for range repeatCount {
repeated = repeated + character
}
return repeated
}

View File

@@ -0,0 +1,22 @@
package iteration
import "testing"
func TestRepeat(t *testing.T) {
got := Repeat("a")
want := "aaaaa"
assertResult(t, got, want)
}
func assertResult(t testing.TB, got, want string) {
t.Helper()
if got != want {
t.Errorf("got %q want %q", got, want)
}
}
func BenchmarkRepeat(b *testing.B) {
for b.Loop() {
Repeat("a")
}
}