Taking an array of records. For example
[ name: 'eventA', timestamp: '2011-08-27 15:34:00', name: 'eventB', timestamp: '2011-08-28 13:31:00', name: 'eventC', timestamp: '2011-08-29 10:34:00', name: 'eventD', timestamp: '2011-08-30 16:36:00', ]
How can I sort these by timestamp in a descending using a standard natural ascending sort algorithm built into most languages. E.g.
collection.Sort(record => record.timestamp)
sort(collection, lambda record: record.timetstamp)
You can not use the
sortByDescending methods, of course most languages have them (or a flag to sort fn for descending)
Somehow have to transform the
record.timestamp so that it sorts descending
Solution 1: Parse the date into a Date object provided by most languages and get time in milliseconds/seconds since 1970. Minus the amount from 0 to get the negated value and sort by this.
Extra points for no expensive date conversions