Comments
Join Hawkee
|
Login
Search
in
Code Snippets
Images
Products
Reviews
Forum
Home
Platforms
Cold Fusion
CSS
Javascript
mIRC
mySQL
.NET
OpenSocial
Perl
PHP
Python
Ruby / Rails
TCL
Images
Snippets
Cold Fusion (1)
CSS (2)
Javascript (7)
mIRC (3,747)
mySQL (1)
.NET (6)
OpenSocial (1)
Perl (8)
PHP (132)
Python (1)
Ruby / Rails (6)
TCL (20)
Products
Computers (10,269)
Electronics (7,320)
Software (1,032)
Video Games (3,485)
Reviews
Computers (5,791)
Electronics (15,502)
Software (2,249)
Video Games (6,895)
Comments
Images
Scripts
Code Snippets
Products
Reviews
Profiles
Forum
username
password
auto login
Home
>
Code Snippets
>
hawker's Snippets
>
Ruby / Rails
sorting
Please
Register
to submit score.
Average Score
6.0
Scores Submitted
1
Date Added
Aug 24, 2005
Last Updated
Aug 24, 2005
Introduction
How to sort an array of strings.
Grab the Code
# Sort array of strings. Strings can be enclosed by # single or double quotes. puts ['foo', 'bar', "apple", "jack"].sort puts "\nNow let's sort in descending order.\n\n" # This time we'll use an easier way to make an array of words. puts %w(foo bar apple jack).sort{ |a,b| b<=>a } puts "\nSorted on last character of each word:\n\n" puts %w(foo bar apple jack).sort_by{ |x| x[-1] }
Comments
(0)
RSS
Go to Bottom
Enter comment here..
Please
Register
or
Login
to start posting comments.
hawker
Last seen:
Aug 25, 2005
Profile
Snippets
(3)
Comments Received
(3)
Contact
Add to Friends
Send Private Message
Sponsors