here after transpose the matrix i want to reverse the row to get the rotation of matrix but until transpose its working after that its not give proper output
import React from "react";
export default function DropDown() {
let matrix = [
[ 1, 2, 3, 4 ],
[ 1, 0, 3, 4 ],
[ 1, 2, 3, 4 ],
[ 1, 2, 3, 4 ],
];
for(let i=0;i<4;i++)
{
for(let j=0;j<i;j++)
{let t;
if(i!=j)
t=matrix[i][j];
matrix[i][j]=matrix[j][i];
matrix[j][i]=t;
}
}
for(let i=0;i<4;i++)
{
for(let j=0;j<4/2;j++)
{let t;
if(i!=j)
t=matrix[i][j];
matrix[i][j]=matrix[i][4-j-1];
matrix[i][4-j-1]=t;
}
}
return (
<>
{matrix.map(i=><div>{i}</div>)}
</>
);
}
I hope you question is about matrix-traspose
const arr = [
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
];
const transpose = arr => {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < i; j++) {
const tmp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = tmp;
};
}
}
transpose(arr);