How does one determine the position of an element present in slice?
I need something like the following:
type intSlice []int func (slice intSlice) p
You could write a function;
func indexOf(element string, data []string) (int) { for k, v := range data { if element == v { return k } } return -1 //not found. }
This returns the index of a character/string if it matches the element. If its not found, returns a -1.