The takeaway shop notes how many minutes each delivery took. Write AvgWait(minutes) to return the average wait (whole minutes, integer division) and nil. With no deliveries there is no average, so return 0 and the error "no deliveries".
AvgWait([]int{20, 30, 40})→(30, None)AvgWait([]int{})→(0, 'no deliveries')func AvgWait(minutes []int) (int, error)package main
// your code here: import "errors"
func AvgWait(minutes []int) (int, error) {
// your code here: no deliveries? return 0 and the error "no deliveries"
total := 0
for _, m := range minutes {
total += m
}
return total / len(minutes), nil
}
Run tries the examples. When they look right, Submit.