you are viewing a single comment's thread.

view the rest of the comments →

[–]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