Stable sort
class Array def stable_sort n = 0 sort_by {|x| n+= 1; [x, n]} end end
TextSnippets > tim > ruby
1775 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
tim
class Array def stable_sort n = 0 sort_by {|x| n+= 1; [x, n]} end end