To rotate 180 degree, reverse rows from bottom to top, then for each row, reverse right to left.
matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] output = [] h = len(matrix) for i in range(h - 1, -1, -1): output.append([x for x in matrix[i]][::-1]) print(output)
const matrix = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
const output = [];
const h = matrix.length;
for (let i = h - 1; i >= 0 ; i--) {
output.push([...matrix[i]].reverse());
}
console.log(output);