Ruby | Array transpose() function
Array#transpose() : transpose() is a Array class method which returns the length of elements in the array transposes the rows and columns.
Syntax: Array.transpose()
Parameter: Array
Return: transposes the rows and columns.
Example #1 :
# Ruby code for transpose() method # declaring arraya = [[18, 22], [33, 3, ], [5, 6]] # declaring arrayb = [[1, 4, 1, 1, 88, 9]] # transpose method exampleputs "transpose() method form : #{a.transpose()}\n\n" puts "transpose() method form : #{b.transpose()}\n\n" |
Output :
transpose() method form : [[18, 33, 5], [22, 3, 6]] transpose() method form : [[1], [4], [1], [1], [88], [9]]
Example #2 :
# Ruby code for transpose() method # declaring arraya = [["abc", "nil", "dog"]] # declaring arrayb = [["cow", "go", "dog"]] # transpose method exampleputs "transpose() method form : #{a.transpose()}\n\n" puts "transpose() method form : #{b.transpose()}\n\n" |
Output :
transpose() method form : [["abc"], ["nil"], ["dog"]] transpose() method form : [["cow"], ["go"], ["dog"]]


