开发者

Get the newest and oldest date from a list - Ruby

开发者 https://www.devze.com 2022-12-09 10:22 出处:网络
I have an array of Ruby Dat开发者_开发百科e objects. How can I find the newest datetime and the oldest datetime?date_array.min # => Oldest

I have an array of Ruby Dat开发者_开发百科e objects. How can I find the newest datetime and the oldest datetime?


date_array.min # => Oldest
date_array.max # => Most recent


oldest, newest =  date_array.minmax


You have a comparison operator:

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

Sort it.

0

精彩评论

暂无评论...
验证码 换一张
取 消