Skip to content
Snippets Groups Projects
recommendation.js 791 B
Newer Older
sacha's avatar
sacha committed

sacha's avatar
sacha committed
/**
 * Cette fonction selectionne les 3 meilleurs movies d'une liste de film.
 *
 * @param {Movie[]} movies - Liste de film.
 * @returns {Movie[]} - La liste des 3 films.
 */

function top3(movies) {
    let highestNotes = [movies[0], movies[0], movies[0]];
    for (let i = 1; i < movies.length; i++) {
        if(movies[i].note >= highestNotes[0].note){
            highestNotes[2] = highestNotes[1];
            highestNotes[1] = highestNotes[0];
            highestNotes[0] = movies[i];
        }else if(movies[i].note >= highestNotes[1].note){
            highestNotes[2] = highestNotes[1];
            highestNotes[1] = movies[i];
        }else if(movies[i].note >= highestNotes[2].note){
            highestNotes[2] = movies[i];
        }
        
    }
    return highestNotes;
}