Reposting from https://medium.com/@kevinle/transpose-a-javascript-array-using-ramda-js-and-es6-syntax-bfd25529b259

This will be a short post because it will set up for my next much longer post. Basically, I need to write a function that transpose an array. I’d like to use Ramda JS and ES6 syntax.

Of course, someone else already asked and several others already answered the question. But since an answer based on Ramda JS and ES6 has not been answered yet, I chime in.

http://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript/29114344#29114344

Here’s my solution:

var transpose = a => {
return R.map(c => {
return R.map(r => {
return r[c];
}, a);
}, R.keys(a[0]));
};

var a = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
];

transpose(a) //=> [[1,5,9],[2,6,10],[3,7,11],[4,8,12]]

And here’s the playground that you can experiment with.