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

256
Views
¿Cómo verificar si la matriz de entrada es simétrica?

El siguiente código toma una matriz ( MAT ) y transpone la matriz, la llama array . La definición de matriz simétrica es que debe ser una matriz cuadrada y los elementos de la matriz dada en comparación con la transpuesta deben ser los mismos.

La matriz dada a continuación y la matriz transpuesta deberían dar como resultado false si se verifica la simetría.

Creé una declaración if al principio para comprobar si MAT[j][i] y array[j][i] son iguales, pero sigo obteniendo la respuesta incorrecta. No está verificando correctamente todos los elementos juntos. ¿Alguien podría ayudar con eso?

¡Gracias!

 const symmetricMatrix = function (MAT) { let array = []; for (let i = 0; i < MAT.length; i++) { array.push([]); for (let j = 0; j < MAT.length; j++) { array[i].push(MAT[j][i]); } } return array; }; console.log( symmetricMatrix( (MAT = [ [1, 3, 1], [-1, 1, 4], [2, 1, 0], ]) ) );

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

0

Primero puede crear una copia de la matriz y luego transponerla y luego verificar si tiene el mismo elemento en ese índice.

 const symmetricMatrix = function (mat) { const copy = Array.from(mat, (_) => []); for (let i = 0; i < mat.length; i++) for (let j = 0; j < mat.length; j++) copy[i][j] = mat[j][i]; for (let i = 0; i < mat.length; i++) for (let j = 0; j < mat.length; j++) if (copy[i][j] != mat[i][j]) return false; return true; }; const matrix = [ [1, 3, 1], [-1, 1, 4], [2, 1, 0], ]; const matrix2 = [ [1, -1, 2], [-1, 1, 1], [2, 1, 0], ]; console.log(symmetricMatrix(matrix)); console.log(symmetricMatrix(matrix2));

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!