The drinks menu is a []Drink (at least one), each with a Name and a Price. Write Cheapest(menu) to return the cheapest one's name; if two cost the same, keep the earlier one.
Cheapest([]Drink{{"latte", 18}, {"tea", 12}, {"mocha", 22}})→'tea'Cheapest([]Drink{{"water", 3}})→'water'func Cheapest(menu []Drink) stringpackage main
type Drink struct {
Name string
Price int
}
func Cheapest(menu []Drink) string {
best := menu[0]
for _, d := range menu {
// your code here: if d is cheaper than best, take d
}
return best.Name
}
Run tries the examples. When they look right, Submit.