views:

56

answers:

2

I have an array of Ruby Date objects. How can I find the most recent datetime and the oldest datetime?

thanks

A: 

You have a comparison operator:

http://www.ruby-doc.org/core/classes/Date.html#M000673

Sort it.

Azeem.Butt
Sorting is lin * log, simply min/max is pure linear.
Thom Smith
Sorting also has many definitions.
Azeem.Butt
+4  A: 
date_array.min # => Oldest
date_array.max # => Most recent
Baldu