```On Oct 30, 10:00 ¨Âí¬ ÂòéáÃáîäìå¼â®ãáîä®®®Àðïâïø®ãïí÷òïôåº
> Josef 'Jupp' Schugt wrote:
> > def datecmp(a, b, reasonable = true)
> >  ¨Âåôõòãíéæ ¨ãíð ¨áòòáÛ²Ý ¼½áòòâÛ²Ý©¡½ > >  ¨Âòåáóïîáâìå
> > cmp = (arra[0] <=> arrb[0])) != 0 ? cmp : (arra[1] <=> arrb[1])
> >  ¨Âìó> > cmp = (arra[1] <=> arrb[1])) != 0 ? cmp : (arra[0] <=> arrb[0])
> >  ¨Âîä
> > end
>
> > date = ['12/01/2007', '11/02/2007', '11/11/2005']
> > puts "reasonable date format"
> > puts date.sort { |a, b| datecmp(a, b) }
> > puts "\nno reasonable date format"
> > puts date.sort { |a, b| datecmp(a, b, false) }
>
> I think you got "reasonable" and "unreasonable" reversed (unless you are
> American :-)
>
> Here is a shorter solution:
>
> MapR = lambda { |x| x.split('/').values_at(2,1,0) }
> MapU = lambda { |x| x.split('/').values_at(2,0,1) }
>
> date = ['12/01/2007', '11/02/2007', '11/11/2005']
> puts "reasonable date format"
> puts date.sort_by(&MapR)
> puts "\nno reasonable date format"
> puts date.sort_by(&MapU)

MAP_R = proc{|x| x.split('/').reverse }
MAP_U = proc{|x| y=x.split('/'); [y.pop,y] }

dates = %w(12/01/2007 11/02/2007 11/11/2005)
puts "reasonable date format"
puts dates.sort_by(&MAP_R)
puts "unreasonable date format"
puts dates.sort_by(&MAP_U)

```