Skip to content

Instantly share code, notes, and snippets.

@CatalinPlesu
Created February 12, 2025 14:37
Show Gist options
  • Select an option

  • Save CatalinPlesu/6c4debb8c2d8d7ca66365b72c03375d5 to your computer and use it in GitHub Desktop.

Select an option

Save CatalinPlesu/6c4debb8c2d8d7ca66365b72c03375d5 to your computer and use it in GitHub Desktop.
Calculates mean per semester and total at Technical University Of Moldova
(function() {
var grades = {};
grades["total"] = { "sum": 0, "count": 0 };
var rows = document.querySelectorAll("table > tbody > tr");
for (i = 0; i < rows.length; i++) {
var semester = rows[i].querySelectorAll("td")[0].innerText;
if (!grades[semester]) {
grades[semester] = { "sum": 0, "count": 0 };
}
var value = parseFloat(rows[i].querySelectorAll("td")[3].innerText.replace(",", "."));
if (value) {
grades[semester]["sum"] += value;
grades[semester]["count"] += 1;
grades["total"]["sum"] += value;
grades["total"]["count"] += 1;
}
}
var response = ""
for (key in grades) {
response += `media in semestrul ${key}: ${grades[key]["sum"]/grades[key]["count"]}\n`;
}
console.log(response);
alert(response);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment