File tree Expand file tree Collapse file tree 2 files changed +39
-30
lines changed Expand file tree Collapse file tree 2 files changed +39
-30
lines changed Original file line number Diff line number Diff line change 1+ import { Teachers } from "./Teachers" ;
2+
13export class StudentGradeCalculator {
2- allYearsTeachers = {
3- 2020 : [
4- [ "Josefina" , true ] ,
5- [ "Edonisio" , true ] ,
6- [ "Edufasio" , false ] ,
7- ] ,
8- 2019 : [
9- [ "Eduarda" , false ] ,
10- [ "Abelardo" , false ] ,
11- [ "Francisca" , false ] ,
12- ]
13- } ;
14-
154 constructor ( yearToCalculate ) {
165 this . yearToCalculate = yearToCalculate ;
6+ this . teachers = new Teachers ( ) ;
177 }
188
199 calculate ( examGrades , hasReachedMinimumClasses ) {
2010 if ( examGrades . length !== 0 ) {
21- let hasToIncreaseOneExtraPoint = false ;
22-
23- for ( let [ year , teachers ] of Object . entries ( this . allYearsTeachers ) ) {
24- if ( ! ( this . yearToCalculate != year ) ) {
25- for ( let teacher of teachers ) {
26- if ( teacher [ 1 ] != true ) {
27- continue ;
28- }
29-
30- hasToIncreaseOneExtraPoint = true ;
31- }
32- } else {
33- continue ;
34- }
35- }
36-
11+
3712 let gradesSum = 0 ;
3813 let gradesWeightSum = 0 ;
3914
@@ -44,7 +19,7 @@ export class StudentGradeCalculator {
4419
4520 if ( gradesWeightSum === 100 ) {
4621 if ( hasReachedMinimumClasses ) {
47- if ( hasToIncreaseOneExtraPoint ) {
22+ if ( this . teachers . isThereAnyBenevolent ( this . yearToCalculate ) ) {
4823 return Math . min ( 10 , gradesSum + 1 ) ;
4924 } else {
5025 return gradesSum ;
Original file line number Diff line number Diff line change 1+ export class Teachers {
2+ allYearsTeachers = {
3+ 2020 : [
4+ [ "Josefina" , true ] ,
5+ [ "Edonisio" , true ] ,
6+ [ "Edufasio" , false ] ,
7+ ] ,
8+ 2019 : [
9+ [ "Eduarda" , false ] ,
10+ [ "Abelardo" , false ] ,
11+ [ "Francisca" , false ] ,
12+ ]
13+ } ;
14+
15+ isThereAnyBenevolent ( yearToCalculate ) {
16+ let isThereAnyBenevolent = false ;
17+
18+ for ( let [ year , teachers ] of Object . entries ( this . allYearsTeachers ) ) {
19+ if ( ! ( yearToCalculate != year ) ) {
20+ for ( let teacher of teachers ) {
21+ if ( teacher [ 1 ] != true ) {
22+ continue ;
23+ }
24+
25+ isThereAnyBenevolent = true ;
26+ }
27+ } else {
28+ continue ;
29+ }
30+ }
31+
32+ return isThereAnyBenevolent ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments