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
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(rotateLeft([[1,2,3],[4,5,6],[7,8,9]]).toString(), [[3,6,9],[2,5,8],[1,4,7]].toString()),
Test.assertEquals(rotateRight([[1,2,3],[4,5,6],[7,8,9]]).toString(), [[7,4,1],[8,5,2],[9,6,3]].toString())
});
});