Re: Sorting help
- From: Peña, Botp <botp@xxxxxxxxxxxxxxxxx>
- Date: Sun, 12 Oct 2008 22:43:26 -0500
From: Binh Ly [mailto:binh@xxxxxxxxxxx]
# Given an array with values like this ["10.1", "7.4", "10.9", "10.11",
# "10.10"]
# when I sort it i get something like ["10.1", "10.10", "10.11", "10.9", "7.4"]
# What is the best way to sort such an array of strings?
# What if the string was extended to "10.1.25".
others have shown split+map
you can also do it w the humble scanf (yes, like c's scanf)
eg,
a.sort_by{|x| x.scanf "%d.%d"}
#=> ["7.4", "10.1", "10.9", "10.10", "10.11"]
- References:
- Sorting help
- From: Binh Ly
- Sorting help
- Prev by Date: Re: regexp with accent insensitive ??
- Next by Date: Re: hitimes 0.3.0 Released
- Previous by thread: Re: Sorting help
- Next by thread: Re: Sorting help
- Index(es):
Relevant Pages
|