Matrix transposition: Difference between revisions

Content added Content deleted
m (→‎JS ES6: Defined transposition of empty matrix)
Line 2,168: Line 2,168:
// transpose :: [[a]] -> [[a]]
// transpose :: [[a]] -> [[a]]
const transpose = xs =>
const transpose = xs =>
xs[0].map(
0 < xs.length ? (
(_, iCol) => xs.map(
xs[0].map(
row => row[iCol]
(_, iCol) => xs.map(
row => row[iCol]
)
)
)
);
) : [];




Line 2,184: Line 2,186:
])
])
);
);



// MAIN ---
// MAIN ---