@main = connection.execute("select code_ver, comment from mastertest
@main contains something like this :
{ [2.1, abcd],
[3.0, xyz],
[2.0, pqr] }
I want to split this array into 2 arrays such that:
@arr1 = {[2.1],
[3.0],
[2.0]}
@arr2 = {[abcd],
[xyz],
[pqr]}
I do something like this to copy one array from another one:
@arr1 = Array.new
@main.each { |r| @arr1.push(r[0]) }
Can something be done here itself to split it how I want it?
Assuming there were some typo’s in your “array” above, a simple
mapwill do the trick:You might also look at
transpose: