Returns the first index at which a given element can be found in the collection, or -1 if it is not present.

Use reflect.ValueOf() to get the array or slice and the value to search for.
Use a for loop with Value.Len() and Value.Index() to iterate over each element and compare it to the search value.
Return the index if a matching value is found, -1 otherwise.

继续阅读 30秒学会 Golang 片段 – IndexOf

Returns a new slice populated with the results of calling the provided function on every element in the collection.

Implement an appropriate function for each type conversion.
Use make() to create an appropriate slice.
Use range to iterate over elements in the given collection, setting the value at the same index in the resulting slice based on the result of fn.
The functions can be tweaked to allow for an index to be passed to fn as a second argument, if desired.

继续阅读 30秒学会 Golang 片段 – Map