Contains Value

Examples in Go
package main

import (
    "fmt"
)

func Index(vs []string, t string) int {
    for i, v := range vs {
        if v == t {
            return i
        }
    }
    return -1
}

func Contains(vs []string, t string) bool {
    return Index(vs, t) >= 0
}

func main() {

    var strs = []string{"peach", "apple", "pear", "plum"}

    fmt.Println(Contains(strs, "grape"))
}
Last Run  :
false