iteration: add simple iteration function
This commit is contained in:
parent
ad9df93776
commit
917ce1638f
12
iteration/iter.go
Normal file
12
iteration/iter.go
Normal 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
12
iteration/iter_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user