1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| class eleve {
constructor(nom, prénom, age, note1, note2, note3, note4) {
this.nom = nom;
this.prenon = prénom;
this.age = age;
this.notes = [ note1, note2, note3, note4 ]
}
get noteMax() {
return Math.max(...this.notes )
}
get noteMin() {
return Math.min(...this.notes )
}
get whoIs() {
return `${this.nom} - ${this.prenon} - ${this.age}ans `
}
}
const unTableauEtudiant
= [ new eleve('a', 'aa', 18, 12, 13, 10, 15)
, new eleve('b', 'bb', 19, 14, 12, 14, 12)
, new eleve('c', 'cc', 17, 13, 19, 10, 8)
, new eleve('d', 'dd', 20, 15, 10, 15, 9)
, new eleve('e', 'ee', 21, 16, 13, 18, 10)
];
const notesMaxMin = unTableauEtudiant.reduce((r,e)=>
{
if ( r.max < e.noteMax) { r.max = e.noteMax; r.elevMax = e.whoIs }
if ( r.min > e.noteMin) { r.min = e.noteMin; r.elevMin = e.whoIs }
return r;
}, {max:0, elevMax:'', min:Number.POSITIVE_INFINITY, elevMin:''} )
console.log( notesMaxMin ) // { max: 19, elevMax: "c - cc - 17ans ", min: 8, elevMin: "c - cc - 17ans " } |
Partager