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

129
Visualizações
Columnas promedio de la tabla HTML en javascript vainilla

Tengo la siguiente función js que una vez presionada genera una tabla.

 function calculateMatrixFact() { var cache = CacheValues(); // split the matrix into arrays one for each user and movie var user_matrix = createGroups(cache.mu, 4); // console.log(user_matrix); var score_matrix = createGroups(cache.ms, 3); //console.log(score_matrix); // remove the string user_name and movie_name for (let i = 0; i < user_matrix.length; i++) { user_matrix[i].shift(); } for (let j = 0; j < score_matrix.length; j++) { score_matrix[j].shift(); } var dot_matrix = []; // perform the dot product for (let j = 0; j < user_matrix.length; j++) { for (let k = 0; k < score_matrix.length; k++) { //console.log(user_matrix[j]) //console.log(score_matrix[k]) var dot_product = (math.multiply(user_matrix[j], score_matrix[k])).toFixed(1); //console.log(dot_product) dot_matrix.push(dot_product); } } // create the matrix and push back the string (first column of the table) var dot_prod_matrix = createGroups(dot_matrix, 5); dot_prod_matrix[0].unshift("Anna"); dot_prod_matrix[1].unshift("Jonny"); dot_prod_matrix[2].unshift("Kimi"); dot_prod_matrix[3].unshift("You"); dot_prod_matrix[4].unshift("Average") //this it the row where I would like to store the avg of each columns. // from array to HTML table fetch = document.getElementById('matrix_factorization'); fetch.innerHTML = `<tr> <th>User</th> <th>Zombieland</th> <th>Modern Times</th> <th>The Grudge</th> </tr>`; for (var i = 0; i < dot_prod_matrix.length; i++) { var newRow = fetch.insertRow(fetch.length); for (var j = 0; j < dot_prod_matrix[i].length; j++) { var cell = newRow.insertCell(j); cell.innerHTML = dot_prod_matrix[i][j]; } } }

Lo que estoy tratando de lograr ahora es calcular también el promedio de cada columna y almacenar el resultado en una quinta fila que he definido. Lo que he tratado de hacer es

 var table = document.getElementById("matrix_factorization"); var avgVal, sumVal = 0; var rowCount = table.rows.length - 2 console.log(rowCount) for (var i = 1; i < table.rows.length; i++) { sumVal = sumVal + parseInt(table.rows[i].cells[1]) } average = sumVal/rowCount

Pero cuando traté de imprimir el valor promedio, tengo NaN.

about 4 years ago · Santiago Gelvez
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