departures = [ 'AMS', 'BCN', 'BBK' ]
sums = {}
departures.each do |d|
sums[d] ||= 0
sums[d] = sums[d] + 1
end
puts( sums )
-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
On Tue, Feb 24, 2009 at 2:57 PM, Remco Swoany
<[email protected]> wrote:
>
> Hi,
>
>
> newbie question(i guess)
>
> a = Bookings.find(:all, :conditions => [3.days.ago])
> a = [id : 1, departure : 'AMS', arrival => 'NY'],[id : 2, departure :
> 'AMS', arrival => 'BCN'],[id : 3, departure : 'AMS', arrival =>
> 'BKK'],[id : 4, departure : 'AMS', arrival => 'BKK'] ect.
>
> The value of the key departure and arrival is dynamic based on
> table(3000 combinations) and the bookings
>
>
> I want to find the bookings and count the arrival and departure(s). I
> the case of the code above, i want the following output.
>
> departure = AMS > total = 5
> arrival = BCN > total = 1
> arrival = NY > total = 1
> arrival = BKK > total = 2
>
> How can i do this
>
> Grtz..remco
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---