summaryrefslogtreecommitdiff
path: root/go/series/series.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-26 09:21:31 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-26 09:21:31 +0200
commit5905c68a1fbae71682ff2edea7c009ad0355e9fb (patch)
tree97c1979119448aa77e2f6f80e2ba2c16be3bf8bd /go/series/series.go
parent8caa9002f4a9ab7a95d73aca5b185ec1da1da6ac (diff)
Solve series
Diffstat (limited to 'go/series/series.go')
-rw-r--r--go/series/series.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/go/series/series.go b/go/series/series.go
new file mode 100644
index 0000000..55f7eb2
--- /dev/null
+++ b/go/series/series.go
@@ -0,0 +1,25 @@
+package slice
+
+// All returns a list of all substrings of s with length n.
+func All(n int, s string) []string {
+ var ret []string
+ for i, j := 0, n; j <= len(s); i, j = i+1, j+1 {
+ ret = append(ret, s[i:j])
+ }
+ return ret
+}
+
+// UnsafeFirst returns the first substring of s with length n.
+func UnsafeFirst(n int, s string) string {
+ if len(s) >= n {
+ return s[:n]
+ }
+ return ""
+}
+
+func First(n int, s string) (string, bool) {
+ if len(s) >= n {
+ return s[:n], true
+ }
+ return "", false
+}