Nicolas Desprès
12/20/2006 3:18:00 PM
On 12/20/06, Josselin <josselin@wanadoo.fr> wrote:
> all happy visitors of Paris know about the 'arrondissement', an
> administrative division of the city... 20 divisions
>
> selecting them from a city table I can map them as :
>
> ['Paris 1' , 'Paris 10' , 'Paris 11' , ..... 'Paris 19' , 'Paris 2' ,
> 'Paris 20' , 'Paris 3' , .... 'Paris 9' ]
>
> is there any way to sort this array and get :
>
> ['Paris 1' , 'Paris 2' , 'Paris 3' , .... 'Paris 9' , 'Paris 10' ,
> 'Paris 11' , ..... 'Paris 19' , 'Paris 20' ]
>
Somethings like (I've not tested the code):
['Paris 1' , 'Paris 2' , 'Paris 3' , .... 'Paris 9' , 'Paris 10' ,
'Paris 11' , ..... 'Paris 19' , 'Paris 20' ].sort do |a, b|
re = /\s(\d+)$/
re.match(a)
ai = $1.to_i
re.match(b)
bi = $1.to_i
ai <=> bi
end
Cheers
--
Nicolas Desprès