Created
December 5, 2013 23:51
-
-
Save nixsticks/7816292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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