-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
127 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
class Subject { | ||
constructor(name, gradesFirstList, gradesSecondList) { | ||
this.name = name; | ||
this.gradesFirst = gradesFirstList; | ||
this.gradesSecond = gradesSecondList; | ||
this._gradesFirst = gradesFirstList; | ||
this._gradesSecond = gradesSecondList; | ||
this.updateAverage(); | ||
}; | ||
|
||
get gradesFirst() { | ||
return this._gradesFirst; | ||
} | ||
|
||
set gradesFirst(grades) { | ||
this._gradesFirst = grades; | ||
updateAverage(); | ||
} | ||
|
||
get gradesSecond() { | ||
return this._gradesSecond; | ||
} | ||
|
||
set gradesSecond(grades) { | ||
this._gradesSecond = grades; | ||
updateAverage(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
docentYT
Author
Owner
|
||
} | ||
|
||
updateAverage() { | ||
this.averageFirstTerm = Subject.average(this.gradesFirst); | ||
this.averageSecondTerm = Subject.average(this.gradesSecond); | ||
this.averageYear = Subject.average(this.gradesFirst.concat(this.gradesSecond)); | ||
} | ||
|
||
static average(gradesList) { | ||
let sum = 0; | ||
let counter = 0; | ||
if (gradesList.length == 0) return (0).toFixed(2); | ||
for (const grade of gradesList) { | ||
if (grade.countToAverage && !isNaN(grade.value)) { | ||
sum += (grade.value * grade.weight); | ||
counter += grade.weight; | ||
} | ||
} | ||
return (sum/counter).toFixed(2); | ||
}; | ||
}; | ||
|
||
|
42 changes: 20 additions & 22 deletions
42
extensions/combined/src/przegladaj_oceny/generateTdsIndexes.js
This file contains 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
This file contains 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
Nie wiem czy w VaniliaJS to jest możliwe, ja bym zrobił dekorator, który dałoby się ustawiać nad setterami. Zadaniem dekoratora byłoby mówienie które settery wywołują konkretną metodę w tym przypadku
updateAverage
. Jeśli nie ma dekoratorów no to to olej.