From: Steve Wilhelm Date: 2010-03-20T06:07:01+09:00 Subject: Re: Grouping elements of an array After reviewing the suggestions, here is my code. records is the result of a ActiveRecord::find with a member called timestamp containing a UNIX timestamp. I introduced an addition of a default value for the find_index call and included a descending sort of the groups. edges = records.each_cons(2).group_by {|(record_x, record_y)| record_y.timestamp - record_x.timestamp < 30 }[false].map{ |edge| edge[0] } groups = records.group_by { |record| edges.find_index {|edge| record.timestamp <= edge.timestamp } || edges.count }.values.sort_by { |e| -e.count } Thanks again for everyone's help. - Steve W. -- Posted via http://www.ruby-forum.com/.