Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
Visibilidad de matrices en javascript ("indefinido")

Intenté calcular la suma de dos matrices (matrices multidimensionales), pero aparece el siguiente mensaje de error:

 Uncaught TypeError: Cannot set properties of undefined (setting '0') at matAdd (matrixCalc.js:28)

cuando hago este código↓. No entiendo por qué "matSum[0][0]" no está definido.

 // M1 + M2 function matAdd(m1, m2){ let matSum = new Array(m1.length); for (let i=0; i<m1.length; i++){ //create a blanco-matrix matSum=new Array(m1[0].length); } if (m1.length == m2.length && m1[0].length==m2[0].length){ for (let i=0; i<m1.length; i++){ for (let j=0; j<m1[0].length; j++){ matSum[i][j]=m1[i][j]+m2[i][j]; //HERE THE ERROR OCCURS } } } else console.log("Dimension-Error") return matSum; }

el código con números de línea

Gracias por la ayuda :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Intenta iniciar tu matriz así

 function matAdd(m1, m2){ let matSum = new Array(m1.length); for (let i=0; i<m1.length; i++){ //create a blanco-matrix matSum [i] =new Array(m1[0].length); // for each column } if (m1.length == m2.length && m1[0].length==m2[0].length){ for (let i=0; i<m1.length; i++){ for (let j=0; j<m1[0].length; j++){ matSum[i][j]=m1[i][j]+m2[i][j]; //HERE THE ERROR OCCURS } } } else console.log("Dimension-Error") return matSum; }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda