The bakery's stock map has how many of each are left, and sold lists the sales in order (one at a time; there's always one to sell). Write SellOut(stock, sold): when something reaches 0, delete it from stock and add its name to a slice, in the order things sold out. Nothing sold out gives an empty slice.
SellOut(map[string]int{"bun": 2, "pie": 1}, []string{"pie", "bun"})→['pie']SellOut(map[string]int{"bun": 1, "tart": 1}, []string{"tart", "bun"})→['tart', 'bun']func SellOut(stock map[string]int, sold []string) []stringpackage main
func SellOut(stock map[string]int, sold []string) []string {
out := []string{}
for _, item := range sold {
stock[item]--
// your code here: if it reached 0, delete it and add its name to out
}
return out
}
Run tries the examples. When they look right, Submit.