Skip to content

Instantly share code, notes, and snippets.

@JosephDunivan
Created May 16, 2017 21:01
Show Gist options
  • Save JosephDunivan/d41496aeaf52dd8f1e4eba2e394a11ce to your computer and use it in GitHub Desktop.
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.
#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