Skip to content

Commit 562023b

Browse files
committed
#22 - JavaScript
1 parent 1325fb1 commit 562023b

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed
Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
//EJERCICIO
22
let arr = [1, 2, 3];
33

4-
//console.log(arr.map((n) => n * 2));
4+
console.log(arr.map((n) => n * 2));
55

66
Array.prototype.customMap = function (callback) {
77
let result = [];
88
for (let i = 0; i < this.length; i++) {
99
let element = callback(this[i]);
1010
result.push(element);
1111
}
12-
1312
return result;
1413
};
1514

16-
//console.log(arr.customMap((n) => n * 2));
15+
console.log(arr.customMap((n) => n * 2));
1716

1817
/*
1918
* DIFICULTAD EXTRA (opcional):
@@ -28,58 +27,33 @@ Array.prototype.customMap = function (callback) {
2827
* - Mayor calificación: Obtiene la calificación más alta de entre todas las
2928
* de los alumnos.
3029
* - Una calificación debe estar comprendida entre 0 y 10 (admite decimales).
31-
32-
let myStudents = [
33-
{
34-
name: 'Ric',
35-
birthDate : new Date(2002, 8, 22),
36-
grades: [6, 7, 9, 7, 8, 9]
37-
},
38-
{
39-
name: 'Eric',
40-
birthDate: new Date(2002, 5, 5),
41-
grades: [9, 8, 9, 7, 9, 8],
42-
},
43-
{
44-
name: 'Rebeca',
45-
birthDate: new Date(2003, 0, 2),
46-
grades: [8, 7, 9, 6, 9, 8],
47-
}
48-
];
49-
*/
30+
*/
5031

5132
let myStudents = [];
5233

5334
class Student {
54-
constructor(name) {
35+
constructor(name, grades, date, month, year) {
5536
this.name = name;
56-
this.grades = [];
57-
}
58-
59-
setBirthdate(date, month, year) {
37+
this.grades = grades;
6038
let birthDateNoFormat = new Date(year, month - 1, date);
6139
this.birthDate = birthDateNoFormat.toLocaleString();
40+
myStudents.push(this);
6241
}
63-
}
6442

65-
function createStudent(name, date, month, year) {
66-
let student = new Student(name);
67-
student.setBirthdate(date, month, year);
68-
myStudents.push(student);
43+
getAverage() {
44+
let result = 0;
45+
this.grades.forEach((element) => {
46+
result = result + element;
47+
});
48+
return result / this.grades.length;
49+
}
6950
}
7051

71-
Array.prototype.getAverage = function () {
72-
let result = 0;
73-
this.forEach((element) => {
74-
result = result + element;
75-
});
76-
return result / this.length;
77-
};
78-
79-
createStudent('Sophie', 12, 3, 2004);
80-
81-
createStudent('David', 23, 5, 2005);
82-
83-
let randomArr = [5, 4, 5, 6, 7];
52+
new Student('Sophie', [8, 8, 7, 9], 12, 11, 2004);
53+
new Student('David', [7, 6, 9, 8], 23, 1, 2005);
54+
new Student('Eliezer', [4, 6, 7, 5], 21, 2, 2005);
55+
new Student('Rebeca', [8, 9, 10, 9], 16, 5, 2005);
8456

85-
console.log(randomArr.getAverage());
57+
myStudents.forEach((element) => {
58+
console.log(`\nEl promedio de ${element.name} es de ${element.getAverage()}`);
59+
});

0 commit comments

Comments
 (0)