Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
rotate matrix 90 degree in clockwise not working properly

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>)}
   </>
);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!