Created
May 16, 2017 21:01
-
-
Save JosephDunivan/d41496aeaf52dd8f1e4eba2e394a11ce to your computer and use it in GitHub Desktop.
Ruby Cuts and array in half and nest it in itself. Divides and Array in half.
This file contains hidden or 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
#Ruby | |
#cuts array in half and nest in new array | |
#can be kept as an Enumerator | |
#useful for creating buckets for dynamic programming | |
#useful for finding palidromes | |
#arrays can be called individually using input[0] or input[1] | |
def cut_in_half(input) | |
input.each_cons(input.length/2).to_a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment