Advertisement
Guest User

Untitled

a guest
May 30th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. ary = [3, 5, 13, 12, 0]
  2.  
  3. # Regular sort, then reverse
  4. ary.sort.reverse
  5. # => [13, 12, 5, 3, 0]
  6.  
  7. # Descending-order sort using a Schwartzian transform
  8. ary.sort_by { |x| -x }
  9. # => [13, 12, 5, 3, 0]
  10.  
  11. # Descending-order sort using map and sort
  12. ary.map { |x| -x }.sort.map { |x| -x}
  13. # => [13, 12, 5, 3, 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement