Last active
June 21, 2022 20:24
-
-
Save salmanmorshed/9c657f66ffd5da195c2609d519a7e848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let finalData = {}; | |
| function collectData() { | |
| const dataTable = document.querySelectorAll('table[style=\'border-collapse:collapse;\'] tr:not([height="30"])'); | |
| for (let row of dataTable) { | |
| let cells = row.cells; | |
| let courseId = cells[1].innerText.trim(); | |
| let courseName = cells[2].innerText.trim(); | |
| let grade = cells[5].innerText.trim(); | |
| let credit = parseFloat(cells[3].innerText.trim()); | |
| if (!(courseId in finalData)) { | |
| finalData[courseId] = { | |
| 'id': courseId, | |
| 'name': courseName, | |
| 'credit': credit, | |
| 'grades': [] | |
| }; | |
| } | |
| finalData[courseId].grades.push(grade); | |
| } | |
| } | |
| function displayData() { | |
| const passGrades = ['D', 'C-', 'C', 'C+', 'B-', 'B', 'B+', 'A-', 'A', 'A+']; | |
| const oldResultTable = document.querySelector("#resultTable"); | |
| if (oldResultTable) oldResultTable.remove(); | |
| const resultTable = document.createElement('table'); | |
| resultTable.id = 'resultTable'; resultTable.border = '1'; resultTable.width = '100%'; | |
| for (let k in finalData) { | |
| let subject = finalData[k]; | |
| if (subject.grades.filter(g => passGrades.includes(g)).length === 0) { | |
| const newTr = document.createElement('tr'); | |
| const tdId = document.createElement('td'); | |
| tdId.innerText = subject['id']; | |
| const tdName = document.createElement('td'); | |
| tdName.innerText = subject['name']; | |
| const tdCredit = document.createElement('td'); | |
| tdCredit.innerText = subject['credit']; | |
| const tdGrades = document.createElement('td'); | |
| tdGrades.innerText = subject['grades']; | |
| newTr.appendChild(tdId); | |
| newTr.appendChild(tdName); | |
| newTr.appendChild(tdCredit); | |
| newTr.appendChild(tdGrades); | |
| resultTable.appendChild(newTr); | |
| } | |
| } | |
| document.querySelector("table[width='100%'][border='0']").parentElement.appendChild(resultTable); | |
| } | |
| collectData(); | |
| displayData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment