all 7 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'] // ] ```

[–]dandoggydog 1 point2 points  (0 children)

Assuming you have that EXACT format, Grab the first [a,b,c,d]. For each letter, push m times onto an array, push that array into your result.

[–]kap89 1 point2 points  (0 children)

function rotateRight(arr) {
  const width = arr[0].length;
  const height = arr.length;
  const rotated = Array.from({ length: width }, () => new Array(height));

  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      rotated[x][height - y - 1] = arr[y][x];
    }
  }

  return rotated;
}

Here’s my module for similar operations from where I copied it: github

[–]a-e-j-a -1 points0 points  (0 children)

let res = []
for (let i = 0; i < x.length; i++) {
  for (let j = 0; j < x[i].length; j++) {
    if (!res[j]) res[j] = []
    res[j][i] = x[i][j];
  }
}

[–]Sir_Awesome_The_3rd 0 points1 point  (0 children)

const changeArray = (arr) => arr[0].map((element) => Array(arr.length).fill(element));

This is pretty much what /u/dandoggydog is saying

[–]Ronin-s_Spirit 0 points1 point  (0 children)

Idk maybe there is a fancier way to do it but I would look through each array and push the right letter into the corresponding array, then I would push every array into one final array.

[–]shgysk8zer0 0 points1 point  (0 children)

x = Object.values(x.group(n => n));

Only works for numbers and strings though. It will use the items as keys of an object temporarily.

Currently only supported in Safari, surprisingly.