iteration: add simple iteration function

This commit is contained in:
vinchent 2024-09-10 13:20:33 +02:00
parent ad9df93776
commit 917ce1638f
2 changed files with 24 additions and 0 deletions

12
iteration/iter.go Normal file
View File

@ -0,0 +1,12 @@
package iteration
const repeatTime = 5
// Repeat takes a string and repeat it 5 times
func Repeat(s string) string {
var res string
for i := 0; i < repeatTime; i++ {
res += s
}
return res
}

12
iteration/iter_test.go Normal file
View File

@ -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)
}
}