Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created June 3, 2013 09:54
Show Gist options
  • Save mattyw/5697203 to your computer and use it in GitHub Desktop.
Save mattyw/5697203 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type BasketItem struct {
Id string
Price int
}
type Basket struct {
Items []BasketItem
}
func TotalPriceOfBasket(basket Basket) int {
total := 0
for _, item := range basket.Items {
total += item.Price
}
return total
}
func main() {
basket := Basket{
[]BasketItem{
BasketItem{"Apples", 5},
BasketItem{"Orange", 6},
},
}
total := TotalPriceOfBasket(basket)
fmt.Printf("Total:%v", total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment