exercism/go/series/slice.go

22 lines
439 B
Go
Raw Normal View History

2016-08-13 23:20:14 +00:00
package slice
// All takes a string 'str' and a length 'l' and returns
// all substrings of length l
func All(l int, str string) []string {
var ret []string
for len(str) >= l {
ret = append(ret, str[:l])
str = str[1:]
}
return ret
}
// Frist (Frist?!) takes a string 'str' and a length 'l' and returns
// the first substring of length l
func Frist(l int, str string) string {
if len(str) >= l {
return str[:l]
}
return ""
}