https://programmers.co.kr/learn/courses/30/lessons/77485?language=javascript
function solution(rows, columns, queries) {
var answer = []
let count=1
let matrix=[]
let row=[]
let temp1,temp2,k,min
for(let i=0;i<rows;i++){
row=[]
for(let j=0;j<columns;j++){
row[j]=count
count++
}
matrix.push(row);
}
for(let query of queries){
temp1=matrix[query[0]-1][query[1]-1]
min=temp1;
for(k=query[1]-1;k<query[3]-1&&k<=columns-1;k++){
temp2=matrix[query[0]-1][k+1]
matrix[query[0]-1][k+1]=temp1
temp1=temp2
if(min>temp1){
min=temp1;
}
}
for(k=query[0];k<query[2]&&k<=rows-1;k++){
temp2=matrix[k][query[3]-1]
matrix[k][query[3]-1]=temp1
temp1=temp2
if(min>temp1){
min=temp1;
}
}
for(k=query[3]-2;k>query[1]-2&&k>=0;k--){
temp2=matrix[query[2]-1][k]
matrix[query[2]-1][k]=temp1
temp1=temp2
if(min>temp1){
min=temp1;
}
}
for(k=query[2]-2;k>query[0]-2&&k>=0;k--){
temp2=matrix[k][query[1]-1]
matrix[k][query[1]-1]=temp1
temp1=temp2
if(min>temp1){
min=temp1;
}
}
answer.push(min)
}
return answer;
}