Skip to content

Instantly share code, notes, and snippets.

@will
Created March 5, 2010 08:24
Show Gist options
  • Save will/322558 to your computer and use it in GitHub Desktop.
Save will/322558 to your computer and use it in GitHub Desktop.
class Array
def split_zip
partition = size/2.0
left = first( partition.ceil )
right = last( partition.floor )
left.zip(right).flatten.compact
end
end
[1].split_zip == [1] # => true
[1,2].split_zip == [1,2] # => true
[1,2,3].split_zip == [1,3,2] # => true
[1,2,3,4].split_zip == [1,3,2,4] # => true
[1,2,3,4,5].split_zip == [1,4,2,5,3] # => true
[1,2,3,4,5,6].split_zip == [1,4,2,5,3,6] # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment