Skip to content

Commit bbc9b58

Browse files
committed
[js][student_grades][extract_class] Extract Teachers class
1 parent 6ae6f74 commit bbc9b58

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

examples/js/js-student_grades-03_extract_class/src/StudentGradeCalculator.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
1+
import {Teachers} from "./Teachers";
2+
13
export 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;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)