-
Notifications
You must be signed in to change notification settings - Fork 1
/
Recipe.go
executable file
·62 lines (48 loc) · 1.21 KB
/
Recipe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Recipe
package main
type Recipe struct {
Cuisine int
Ingredients []string
UniqueID int
}
func NewRecipe2(cuisine int) (recp *Recipe) {
recp = new(Recipe)
recp.Cuisine = cuisine
recp.Ingredients = make([]string, 0)
return recp
}
func NewRecipe(cuisine int, ingredients []string) (recp *Recipe) {
recp = new(Recipe)
recp.Cuisine = cuisine
recp.Ingredients = ingredients
return recp
}
func (recp *Recipe) AddIngredient(ingr string) {
recp.Ingredients = append(recp.Ingredients, ingr)
}
func (recp *Recipe) hasIngredient(testIngredient string) bool {
for _, ingr := range recp.Ingredients {
if ingr == testIngredient {
return true
}
}
return false
}
func (recp *Recipe) getIngredientCount(ingredientName string) (count int, found bool) {
for _, ingr := range recp.Ingredients {
if ingr == ingredientName {
found = true
}
}
return count, found
}
func (recp *Recipe) getUniqueIngredients() (ingredients map[string]bool) {
ingredients = make(map[string]bool)
for _, ingr := range recp.getIngredients() {
ingredients[ingr] = true
}
return ingredients
}
func (recp *Recipe) getIngredients() []string {
return recp.Ingredients
}