Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
How to check if the input matrix is symmetric?

The code below takes in a matrix (MAT) and transposes the matrix, calls it array. The definition of the symmetrical matrix is that it should be a square matrix and the elements in the given matrix compared to the transposed one should be the same.

The given matrix below and transposed matrix should output false if checked for symmetry.

I did create an if statement at first to check whether MAT[j][i] and array[j][i] are the same but keep getting the wrong answer. It's not properly checking all the elements together. Could someone help with that?

Thanks!

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 Respuestas
Responde la pregunta

0

First you can create a copy of matrix and then transpose it and then check if it has same element at that index.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda