def f(a) b = a.select(&:odd?).sort a.map {|n| n.odd? ? b.shift : n}endp f [6, 5, 4, 3, 2, 1]p f [6, 5, 3, 1]
Standard input is empty
[6, 1, 4, 3, 2, 5] [6, 1, 3, 5]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!