Skip to content

Instantly share code, notes, and snippets.

@pastafari
Created August 2, 2012 23:47
Show Gist options
  • Save pastafari/3242172 to your computer and use it in GitHub Desktop.
Save pastafari/3242172 to your computer and use it in GitHub Desktop.
Array#transpose using inject and collect (http://rubeque.com/problems/implement-array-hash-transpose)
class Array
def transpose
empty? ? [] : inject {|memo, ary| memo.zip(ary)}.collect(&:flatten)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment