diff --git a/_content/doc/play/index-dev.txt b/_content/doc/play/index-dev.txt new file mode 100644 index 00000000..7fa3a0e1 --- /dev/null +++ b/_content/doc/play/index-dev.txt @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" +) + +// The index function returns the index of the first occurrence of v in s, +// or -1 if not present. +func index[E comparable](s []E, v E) int { + for i, vs := range s { + if v == vs { + return i + } + } + return -1 +} + +func main() { + s := []int{1, 3, 5, 2, 4} + fmt.Println(index(s, 3)) + fmt.Println(index(s, 6)) +} diff --git a/_content/doc/play/min-dev.txt b/_content/doc/play/min-dev.txt deleted file mode 100644 index 09a4bf3f..00000000 --- a/_content/doc/play/min-dev.txt +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "fmt" - "constraints" -) - -func min[P constraints.Ordered](x, y P) P { - if x < y { - return x - } else { - return y - } -} - -func main() { - fmt.Println(min(42, 24)) -} diff --git a/_content/play.tmpl b/_content/play.tmpl index f7abe78d..65d63659 100644 --- a/_content/play.tmpl +++ b/_content/play.tmpl @@ -36,7 +36,7 @@ - +