Example 1 — Official Samples
The three samples from the Ramda docs: tall to wide, wide to tall, and uneven rows.
console.log(R.transpose([[1, 'a'], [2, 'b'], [3, 'c']])); // [[1, 2, 3], ['a', 'b', 'c']]
console.log(R.transpose([[1, 2, 3], ['a', 'b', 'c']])); // [[1, 'a'], [2, 'b'], [3, 'c']]
console.log(R.transpose([[10, 11], [20], [], [30, 31, 32]])); // [[10, 20, 30], [11, 31], [32]] How It Works
- Tall to wide. 3 rows of 2 items become 2 rows of 3: all first items, then all second items.
- Wide to tall. 2 rows of 3 become 3 rows of 2 — the reverse of the first call.
- Uneven rows. Rows that are too short add nothing to a column, so column 1 is just
[11, 31]. - New arrays. Every call returns a fresh 2D list; the inputs are not changed.
