Since nobody so far mentioned a functional recursive approach here is my take. An adaptation of Haskell's Data.List.transpose
.
var transpose = as => as.length ? as[0].length ? [as.reduce((rs, a) => a.length ? (rs.push(a[0]), rs) :
rs, []
), ...transpose(as.map(a => a.slice(1)))] :
transpose(as.slice(1)) :
[],
mtx = [
[1],
[1, 2],
[1, 2, 3]
];
console.log(transpose(mtx))
_x000D_
.as-console-wrapper {
max-height: 100% !important
}
_x000D_