This post originated from an RSS feed registered with Ruby Buzz
by Matthew Bass.
Original Post: How to safely transpose Ruby arrays
Feed Title: Pelargir
Feed URL: http://feeds.feedburner.com/pelargir/
Feed Description: Musings on software and life from Matthew Bass. Regular posts on new web products, tips and tricks, etc.
Ruby arrays have this handy method called transpose which takes an existing 2-dimensional array (i.e. a matrix) and flips it on its side:
>> a = [[1,2], [3,4], [5,6]]
>> puts a.transpose.inspect
[[1, 3, 5], [2, 4, 6]]
Each row becomes a column, essentially. This is fine and dandy for polite arrays. If one of the rows in the [...]