Skip to content

Instantly share code, notes, and snippets.

@adambard
Created August 3, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adambard/2e2af4d31705efe5e41bd58283276a7d to your computer and use it in GitHub Desktop.
Save adambard/2e2af4d31705efe5e41bd58283276a7d to your computer and use it in GitHub Desktop.
calculatesum=function(html){
//! This function doesn't seem to do anything, since it's only ever called with an element's innerHTML.
var tmp = document.createElement("DIV")
tmp.innerHTML = html
return tmp.textContent||tmp.innerText
}
getColumnCount=function()
{
return document.getElementById('tableEff').getElementsByTagName('tr')[0].getElementsByTagName('td').length;
}
getRowCount=function()
{
//! There is no property "rows" of Element:
//! https://developer.mozilla.org/en-US/docs/Web/API/Element
return document.getElementById('tableEff').rows.length;
}
resultEff=function(){
//! Why -1? You use < in the loops (-1 is if you used <=)
var lastCol = getColumnCount()-1;
var lastRow = getRowCount()-1;
var tbl = document.getElementById("tableEff");
var NbCol=16; // Why not use column count?
var totals = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
//! Why not getColumnCount?
//! Also, you call `.length` on numbers, twice.
for (var i = 0; i < NbCol.length; i++){
for (var j = 0; j < lastRow.length; j++){
var cell = lastRow[j].NbCol[i]
//! Still not sure what calculatesum is doing here. Why not just innerText directly?
var num = parseInt(calculatesum(cell.innerHTML), 10)
/*alert(parseInt(calculatesum(cell.innerHTML), 10))
console.log(parseInt(calculatesum(cell.innerHTML), 10))*/
totals[i] += num
// alert(totals[i])
console.log(totals[i])
}
}
console.log(totals[i])
/*document.getElementById('TotalEff').innerHTML = "test: " + totals[1]
console.log(totals[0])*/
//alert(totals[0])
var contenuTable=""
for(var i = 0; i < 15; i++){
contenuTable += "<td>" + totals[i] + "</td>"
}
var Table= document.getElementById('table-totaux').innerHTML // an other table for the result
//var trTable= Table.getElementsByTagName("tr").value
//var Table.innerHTML(contenuTable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment