Given an array:
arr = [['a', '1'], ['b','2'], ['c', '3']]
Whats the best way to split it into two arrays?
For example from the array above I want to get the following two arrays:
first = ['a','b','c']
second = ['1', '2', '3']
Can i do this using collect?
ok i just stumbled upon
arr.transposecompared to the answers above
arr.zip,arr.map, and theforeach, which is more efficient?Or which is the most elegant solution?
OR
(Thanks to comment by Jörg W Mittag – see comment below)
first, second =
arr.transpose