Re: [QUIZ] Price Ranges (#164)
by Sharon and Dave other posts by this author
Jun 6 2008 5:22AM messages near this date
[QUIZ] Price Ranges (#164)
|
Re: Price Ranges (#164)
Here's my quick attempt
Cheers,
Dave
-----------------------------
def select_shops shops, wanted_min, wanted_max
shops.select do |shop|
(wanted_max ? wanted_max> = shop[:prices].min : true) &&
(wanted_min ? wanted_min<= shop[:prices].max : true)
end
end
shops= [{:name=> 'Company A', :prices=> 1_000.. 3_000},
{:name=> 'Company B', :prices=> 6_000..10_000},
{:name=> 'Company C', :prices=> 500.. 2_500}]
select_shops(shops, 2_500, 4_000).each do |shop|
puts shop[:name]
end
Thread:
Matthew Moss
Sharon and Dave
Matthew Rudy Jacobs
Sharon and Dave
Steven Hahn
Harry Kakueki
Toby O'Rourke
jgabrielygalan
Steven Hahn
Andrea Fazzi
S2
Matthew Moss
Matthew Moss
Robert Dober
|