package inventory type Inventory struct { Items []Item } type Item struct { Title string Quantity int } func (m *Inventory) Add(title string) { for _, v := range m.Items { if v.Title == title { v.Quantity++ return } } m.Items = append(m.Items, Item{Title: title, Quantity: 1}) } func (m *Inventory) Del(title string) int { for i, v := range m.Items { if v.Title == title { count := v.Quantity m.Items = append(m.Items[:i], m.Items[i+1:]...) return count } } return 0 }