const arr1 = [['a', 'b'], ['1', '2'], ['+', '-']]
const arr2 = [['a', 'b', 'c'], ['1', '2', '3'], ['+', '-', '*']]
const result = [['a', '1', '+'], ['b', '2', '-']]
const result = [['a', '1', '+'], ['b', '2', '-'], ['c', '3', '*']]
const transpose = matrix => Array.from(
{ length: matrix[0]?.length ?? 0 },
(_, i) => matrix.map(n => n[i])
);
function transpose(matrix) {
const result = Array(matrix.length && matrix[0].length);
for (let i = 0; i < result.length; i++) {
result[i] = [];
for (let j = 0; j < matrix.length; j++) {
result[i][j] = matrix[j][i];
}
}
return result;
}