Created
October 19, 2011 21:37
-
-
Save mattfitzgerald/1299767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sort an array with one known special value first. | |
# so given | |
arr = [{:val => 23},{:val => 46},{:val => 65464},{:val => 33},{:val => 50}] | |
# sort the array so {:val => 33} is first and the rest are ordered by their :val vlaues. | |
arr.sort{|a,b| | |
if a[:val] == 33 | |
-1 | |
elsif b[:val] == 33 | |
1 | |
else | |
a[:val] <=> b[:val] | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment