Skip to content

Instantly share code, notes, and snippets.

@mattfitzgerald
Created October 19, 2011 21:37
Show Gist options
  • Save mattfitzgerald/1299767 to your computer and use it in GitHub Desktop.
Save mattfitzgerald/1299767 to your computer and use it in GitHub Desktop.
# 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