Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wishlist = [
- {:name => "mini puzzle", :size => "small", :clatters => "yes", :weight => "light"},
- {:name => "toy car", :size => "medium", :clatters => "a bit", :weight => "medium"},
- {:name => "card game", :size => "small", :clatters => "no", :weight => "light"}
- ]
- presents = [
- {:size => "medium", :clatters => "a bit", :weight => "medium"},
- {:size => "small", :clatters => "yes", :weight => "light"}
- ]
- # guess_gifts(wishlist, presents) # must return ['toy car', 'mini puzzle']
- def guess_gifts(wishlist, presents)
- sizes = wishlist.map{|item| item[:size]}
- weights = wishlist.map{|item| item[:weight]}
- clatters = wishlist.map{|item| item[:clatters]}
- gifts = []
- presents.each do |present|
- guess = wishlist.find{|gift| present[:size] == gift[:size] &&
- present[:clatters] == gift[:clatters] &&
- present[:weight] == gift[:weight] }
- gifts << guess[:name]
- end
- return gifts
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement