My hacking journal

Join multidimensional array elements with a Ruby oneliner

· by admin · Read in about 1 min · (36 Words)
oneliner ruby

Just the code

matrix = Array[
[1, 2, 3],
[4, 5, 6],
[0, 0, 0]
]
puts matrix[0..1].transpose.map {|col| col.join(', ')}.join(', ')
>>> 1, 4, 2, 5, 3, 6

I thought of this because of canvas.setTransform()

Comments