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

123
Views
su matriz anxn 2d que representa una imagen, gira la imagen 90 grados

su matriz anxn 2d que representa una imagen, cómo rotar la imagen 90 grados [[1,2,3],[4,5,6],[7,8,9]] a [[7,4,1], [8,5,2],[9,6,3]]?

 function rotate(matrix){ for(let r=0;r<matrix.length;r++){ for(let c=r;c<matrix[0].length;c++){ [matrix[r][c],matrix[c][r]] = [matrix[c][r],matrix[r][c]] } } for(row of matrix){ return row.reverse() } } console.log(rotate([[1,2,3],[4,5,6],[7,8,9]]))

la salida solo muestra [7,4,1]

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tiene una declaración de retorno incondicional en un bucle. Eso no tiene sentido. La función siempre devuelve la primera row.reverse() . Mueva la declaración de retorno fuera del bucle:

 function rotate(matrix){ for(let r=0;r<matrix.length;r++){ for(let c=r;c<matrix[0].length;c++){ [matrix[r][c],matrix[c][r]] = [matrix[c][r],matrix[r][c]] } } for(row of matrix){ row.reverse() } return matrix; } console.log(rotate([[1,2,3],[4,5,6],[7,8,9]]))

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!