From: Josh Cheek Date: 2010-03-19T12:29:42+09:00 Subject: Re: Grouping elements of an array --000e0cd146f821cccb04821ef551 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 18, 2010 at 4:50 PM, Steve Wilhelm wrote: > I have an array of records that contain timestamps at random intervals. > The records are ordered by timestamp. > > I would like to convert the array into an array of arrays; each subarray > would contain "grouped records." Grouping would occur if the timestamp > of the next element in the original array is within thirty seconds of > the current element. > > Example (second column is timestamp in seconds starting from zero). > > A 0 > B 15 > C 35 > D 100 > E 205 > F 215 > G 300 > > would result in > > [[A, B, C], [D], [E, F], [G]] > > Any help on how to do this in the "Ruby Way" would be appreciated. > > - Steve W. > -- > Posted via http://www.ruby-forum.com/. > > Here is my solution, it's conceptually similar to Roger's, though differs in implementation http://gist.github.com/337195 --000e0cd146f821cccb04821ef551--