To rotate 90 degree, select each column from left to right into a new list, reverse the list and append result to output.
matrix = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
output = []
h = len(matrix)
w = len(matrix[0])
for i in range(w):
c = []
for j in range(h):
c.append(matrix[j][i])
output.append(c[::-1])
print(output)
const matrix = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
const output = [];
const h = matrix.length;
const w = matrix[0].length;
for (let i = 0; i < w ; i++) {
let c = [];
for (let j = 0; j < h; j++) {
c.push(matrix[j][i]);
}
output.push(c.reverse());
}
console.log(output);