From: Paul Date: 2010-09-23T23:20:16+09:00 Subject: Re: Sorting problem with an Array of Arrays On Sep 23, 3:22 am, Jesús Gabriel y Galán wrote: > > Does this mean the array has to be sorted based on timestamps (i.e: > the second element of each subarray)? Yes and no. I can't sort by timestamps as a primary sort. > > > When sorted correctly, I can see the data input problem with the > > 'ABC-3' time stamp.  The label sort is important except when the > > labels change, then they need to be sorted numerically. > > I don't understand this. What do you mean by "when the labels change?" > > Jesus. The arrays represent timesheet records for work done. Each person on the crew submits their records but sometimes they work on projects with others. The majority of the record labels will be for a single person (e.g. the ABC-*) but from time to time a different label will show up (AAA, DEF, ...) because they worked a project with someone else. The ruby script I have goes through the list of records and looks for double-bookings and other mistakes made during data entry. For example, sometimes someone writes 10 PM when it was 10 AM. That's why the label order is primary - it represents the order in which the jobs happened. The timestamps themselves might be wrong. However, when a new/different label appears, the "best guess" scenario is to insert it into the list according to timestamp and rerun the analysis to check that the timestamps are correct (no double-bookings, etc.) I wrote a method that does a recursive analysis on the data using 2 separately sorted arrays - one by label and one by timestamp. It's weird and a bit complex but it works. If I could find a way to sort the data properly in the first place, then I can simplify the code checking that takes place after it. Does this help? TIA.