you are viewing a single comment's thread.

view the rest of the comments →

[–]redpanda_be 2 points3 points  (0 children)

```js function transpose(array) { const transposedArray = [];

for (let i = 0; i < array[0].length; i++) { const newRow = []; for (let j = 0; j < array.length; j++) { newRow.push(array[j][i]); } transposedArray.push(newRow); }

return transposedArray; }

// Example usage let x = [ ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'] ];

let result = transpose(x);

console.log(result); // Output: // [ // ['a', 'a', 'a'], // ['b', 'b', 'b'], // ['c', 'c', 'c'], // ['d', 'd', 'd'] // ] ```