Transpose

R

Robert Klemme

This occurred to me while lying sick in bed...

robert@fussel /cygdrive/c/Temp
$ ruby dd.rb
[["foo", "bar", "baz", "biz"], [1, 2, 3, 4], [100, 200, 300, 400]]
[["foo", 1, 100], ["bar", 2, 200], ["baz", 3, 300], ["biz", 4, 400]]

robert@fussel /cygdrive/c/Temp
$ cat dd.rb

require 'enumerator'
require 'pp'

def transpose(a)
a.inject {|aa,b| aa.to_enum:)zip, b)}.inject([]){|aa,b| aa << b.flatten}
end

a = [
%w{foo bar baz biz},
[1,2,3,4],
[100,200,300,400],
]

pp a, transpose(a)


Did we have this before?

Whatever...

robert
 
T

Tim Pease

This occurred to me while lying sick in bed...

robert@fussel /cygdrive/c/Temp
$ ruby dd.rb
[["foo", "bar", "baz", "biz"], [1, 2, 3, 4], [100, 200, 300, 400]]
[["foo", 1, 100], ["bar", 2, 200], ["baz", 3, 300], ["biz", 4, 400]]

robert@fussel /cygdrive/c/Temp
$ cat dd.rb

require 'enumerator'
require 'pp'

def transpose(a)
a.inject {|aa,b| aa.to_enum:)zip, b)}.inject([]){|aa,b| aa << b.flatten}
end

a = [
%w{foo bar baz biz},
[1,2,3,4],
[100,200,300,400],
]

pp a, transpose(a)


Did we have this before?

Whatever...


a = [
%w{foo bar baz biz},
[1,2,3,4],
[100,200,300,400],
]

a.transpose


Blessings,
TwP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,230
Messages
2,571,161
Members
47,796
Latest member
AlphonseNa

Latest Threads

Top