Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

40 lines
728 B

package main
import (
"fmt"
"strings"
)
func main() {
hdr := []string{"empid", "employee", "address", "hours worked",
"hourly rate", "manager"}
result := csvHdrCol(hdr)
fmt.Println("Result:")
fmt.Println(result)
fmt.Println()
hdr2 := []string{"employee", "empid", "hours worked", "address",
"manager", "hourly rate"}
result2 := csvHdrCol(hdr2)
fmt.Println("Result2:")
fmt.Println(result2)
fmt.Println()
}
func csvHdrCol(hdr []string) map[int]string {
csvIdxToCol := make(map[int]string)
for i, v := range hdr {
v = strings.TrimSpace(v)
switch strings.ToLower(v) {
case "employee", "hours worked", "hourly rate":
csvIdxToCol[i] = v
}
}
return csvIdxToCol
}