Created
April 14, 2018 13:30
-
-
Save eoo/13c156f267a6df6251a5d580b22c0f97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: movie_search(movie_list, genre, top) | |
Parameters: movie_list: the list containing movie objects | |
genre(optional, default = "Action"): the genre for which you want to search | |
top (optional, default = 3): the number of top results to show | |
*/ | |
function movie_search(data, genre = "Action", top = "3"){ | |
var list = []; | |
for (let movie of data ) { | |
for (let x of movie.genre){ | |
if ( x.includes(genre) ) list.push(movie); | |
} | |
} | |
list.sort((a, b) => b.imdb_score - a.imdb_score); | |
console.log("Top " + top + " " + genre + " movies are : \n"); | |
for (let x = 0; x < Math.min(top,list.length); x++){ | |
console.log( x+1 + ". Movie: " + list[x].name + "\n Director: " + list[x].director + "\n\n" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment