Created
March 5, 2010 08:24
-
-
Save will/322558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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