Ad

Rotate the elements in a 3-dimensional array 90 degrees to the left or to the right.

const rotateLeft = (arr) => {
  let retArr = [[],[],[]]
  for (let i = 0; i < arr.length; i++){
    for (let j = 0; j < arr[i].length; j++){
      retArr[i][j] = arr[j][arr.length - (i + 1)]
    }
  }
  return retArr
}

const rotateRight = (arr) => {
  let retArr = [[],[],[]]
  for (let i = 0; i < arr.length; i++){
    for (let j = 0; j < arr[i].length; j++){
      retArr[i][j] = arr[arr.length - (j + 1)][i]
    }
  }
  return retArr
}