public get nom(): string {return <string> this._nom;} public get notes(): number[] {return <number[]> this._notes;} public set nom(_nom:string) {this._nom = _nom;} public set notes(_notes:number[]) {this._notes = _notes;} public calculerMoyenne = (): number => this.notes.reduce((a,b) => a+b) / this.notes.length; public trouverMax = (): number => this.notes.reduce((a,b) => a>b ? a:b); public trouverMin = (): number => this.notes.reduce((a,b) => a<b ? a:b);} import {Stagiaire} from "./Stagiaire" export class Formation { constructor(private _intitule?:string, private _nbrJours?:number, private _stagiaires?: Stagiaire[]) {} public get intitle():string {return <string> this._intitule;} public get nbrJours():number {return <number> this._nbrJours;} public get stagiaires():Stagiaire[] {return <Stagiaire[]> this._stagiaires;} public set intitle(_intitule:string) {this._intitule = _intitule;} public set nbrJours(_nbrJours:number) {this._nbrJours = _nbrJours;} public set stagiaires(_stagiaires:Stagiaire[]) {this._stagiaires = _stagiaires;} public calculerMoyenneFormation = ():number => this.stagiaires.map(s => s.calculerMoyenne()).reduce((a,b) => a+b) / this.stagiaires.length; /*public getIndexMax = ():number => { let moyMax: number = this.stagiaires.map(s => s.calculerMoyenne()).reduce((a,b) => a>b ? a:b); return this.stagiaires.map(s => s.calculerMoyenne()).indexOf(moyMax);}*/ public getIndexMax = ():number => {let moyMax: number[] = this.stagiaires.map(s => s.calculerMoyenne()); return moyMax.indexOf(Math.max(...moyMax));} public afficherNomMax = (): void => console.log("Meilleure stagiaire: "+this.stagiaires[this.getIndexMax()].nom); public afficherMinMax = (): void => console.log("Note minimale: "+this.stagiaires[this.getIndexMax()].trouverMin()); public trouverMoyenneParNom = (nom: string): void => console.log("Le moyenne de "+nom+": "+this.stagiaires.filter(s => s.nom == nom).map(s => s.calculerMoyenne()))} import { Stagiaire } from './stagiaire';import { Formation } from './formation';
let stagiaire1: Stagiaire = new Stagiaire("Ali", [12, 14, 16]);
let stagiaire2: Stagiaire = new Stagiaire("Amine", [10, 12, 14]); let stagiaire3: Stagiaire = new Stagiaire("Malek", [6, 14, 10]); let formation1: Formation = new Formation("Angular",30,[stagiaire1,stagiaire2, stagiaire3]);