Map To
Examples
Filter
package main
import (
"fmt"
"strings"
)
func Map(vs []string, f func(string) string) []string {
vsm := make([]string, len(vs))
for i, v := range vs {
vsm[i] = f(v)
}
return vsm
}
func main() {
var strs = []string{"peach", "apple", "pear", "plum"}
fmt.Println(Map(strs, strings.ToUpper))
}
Last Run
:
[PEACH APPLE PEAR PLUM]