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

111
Visualizações
Matrix transpose JS

Functions that output the transpose of a matrix - a new matrix where the columns and rows of the original are swapped. I'm trying to figure out why the second function outputs incorrect results?

function transpose(matrix) {
    let res = [];
    for(let i = 0;  i < matrix[0].length; i++) {
        res[i] = [];
        for(let j = 0;  j < matrix.length; j++) {
            res[i][j] = matrix[j][i];
        }
    }
    return res; 
}

function transpose(matrix) {
    let res = Array(matrix[0].length).fill([]);
    for(let i = 0;  i < res.length; i++) {
        for(let j = 0;  j < matrix.length; j++) {
            res[i][j] = matrix[j][i];
        }
    }
    return res; 
}
about 4 years ago · Juan Pablo Isaza
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