1
2
3
4
5
6
7
8
9
10
11
12
| func Find(slice []string, val string) (int, bool) {
for i, item := range slice {
if item == val {
return i, true
}
}
return -1, false
}
items := []string{"A", "1", "B", "2", "C", "3"}
k, found := Find(items, "B")
// found=true, k=2
|