main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function flip(matrix){
  var N = matrix.length;
  var temp; 
  
  for (var Layer = 0; Layer < (N/2); Layer ++){
    for (var Pos = Layer; Pos < N - Layer - 1; Pos++){
      temp = matrix[Layer][Pos]; 
      matrix[Layer][Pos] = matrix[N-Pos-1][Layer]; 
      matrix[N-Pos-1][Layer] = matrix[N-Layer-1][N-Pos-1];  
      matrix[N-Layer-1][N-Pos-1] = matrix[Pos][N-Layer-1]; 
      matrix[Pos][N-Layer-1] = temp; 
    }
  }
  
  return matrix; 
}

console.log(flip([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]));
console.log('\n');
console.log(flip([[1,2,3],[4,5,6],[7,8,9]])); 
Native Browser JavaScript