I have a list of posts ordered by most recent date of modification. I want to stagger them into two columns to have the two recent modified posts at the top. This code is fairly self explanatory:
posts.each do |post|
right_column << post if shift
left_column << post if !shift
shift = shift ? false : true
end
posts = left_column + right_column
For example, given the input [1, 2, 3, 4], the goal is to produce [1, 3, 2, 4].
Is there a more elegant/idiomatic way to achieve this in Ruby?