Skip to content

Instantly share code, notes, and snippets.

@nixsticks
Created December 5, 2013 23:51
Show Gist options
  • Save nixsticks/7816292 to your computer and use it in GitHub Desktop.
Save nixsticks/7816292 to your computer and use it in GitHub Desktop.
ITEMS = [ {"AVOCADO" => {:price => 3.00, :clearance => true}},
{"KALE" => {:price => 3.00,:clearance => false}},
{"BLACK_BEANS" => {:price => 2.50,:clearance => false}},
{"ALMONDS" => {:price => 9.00, :clearance => false}},
{"TEMPEH" => {:price => 3.00,:clearance => true}},
{"CHEESE" => {:price => 6.50,:clearance => false}},
{"BEER" => {:price => 13.00, :clearance => false}},
{"PEANUTBUTTER" => {:price => 3.00,:clearance => true}},
{"BEETS" => {:price => 2.50,:clearance => false}}]
COUPS = [ {:item=>"AVOCADO", :num=>2, :cost=>5.00},
{:item=>"BEER", :num=>2, :cost=>20.00},
{:item=>"CHEESE", :num=>3, :cost=>15.00}]
def coupon_clearance
COUPS.each do |coupon|
ITEMS.each do |item|
item.each do |name, values|
coupon[:cost] = coupon[:cost] * 0.8 if name == coupon[:item] && values[:clearance]
end
end
end
end
def generateCart
cart = []
rand(1..20).times do
cart.push(ITEMS.sample)
end
cart
end
def updateCart(cart)
cart.each do |item|
item.each do |name, attributes|
attributes[:count] = cart.select{|other_item| other_item == item}.size
end
end
cart.uniq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment