Skip to content

Instantly share code, notes, and snippets.

Created November 21, 2013 18:03
What would you like to do?
Ordering an array in Ruby using 2 sorting criterias
# Ordering a list by field1 in descending order. If two elements have the same value, order by field2 in ascending order
list.sort do |a, b|
comp = (b.field1 <=> a.field2) ? (a.field2 <=> b.field2) : comp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment