Last active
December 17, 2015 21:39
-
-
Save SteveBenner/5676567 to your computer and use it in GitHub Desktop.
Divide an array into equal halves
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
# @return [Array] Two-member Array containing self evenly split into two sub-arrays | |
# @example | |
# [1,2,3,4].halves #=> [[1,2],[3,4]] | |
# [1,2,3].halves #=> [[1,2],[3]] | |
def halves | |
[self[0..(self.size/2.0).round-1], self[(self.size/2.0).round..self.size]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment