Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adrian Burke 9-4-mid-module-two #11

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 74 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const exampleMovies = require("./movies");
"James and the Giant Peach",
];
*/
function getAllMovieTitles() {}
function getAllMovieTitles(movies) {
if (movies.length === 0) {
throw ('Error')
}
return movies.map(movie => movie.title)
}

/**
* checkIfAnyMovieHasRating()
Expand All @@ -50,7 +55,15 @@ function getAllMovieTitles() {}
* checkIfAnyMovieHasRating(movies, "R");
* //> false
*/
function checkIfAnyMovieHasRating() {}
function checkIfAnyMovieHasRating(movies, rating="G") {
if (movies.length === 0){
throw ('Error')
}
let myRes = movies.some((movie) => {
return movie.rated === rating;
});
return myRes
}

/**
* findById()
Expand All @@ -68,7 +81,21 @@ function checkIfAnyMovieHasRating() {}
// Toy Story 4
};
*/
function findById() {}
function findById(movies, id) {
if (movies.length === 0){
throw ("Error")
}
let movieId = movies.find((movie) => {
if (movie.imdbID === id){
return movie;
}
});
if (movieId === 0){
return null;
} else {
return movieId;
}
}

/**
* filterByGenre()
Expand All @@ -92,7 +119,17 @@ function findById() {}
* filterByGenre(movies, "Horror")
* //> []
*/
function filterByGenre() {}
function filterByGenre(movies , genre) {
if (movies.length === 0){
throw ('Error')
}
let genreOfMovie = movies.filter((movie) => {
if (movie.genre.toUpperCase().includes(genre.toUpperCase())) {
return movie;
}
});
return genreOfMovie
}

/**
* getAllMoviesReleasedAtOrBeforeYear()
Expand All @@ -118,7 +155,16 @@ function filterByGenre() {}
}
];
*/
function getAllMoviesReleasedAtOrBeforeYear() {}
function getAllMoviesReleasedAtOrBeforeYear(movies, year) {
if (movies.length === 0) {
throw('Error')
}
let moviesByYear = movies.filter((movie) => {
return movie.released.substring(movie.released.length - 4) <= year;
});

return moviesByYear;
}

/**
* checkMinMetascores()
Expand All @@ -134,7 +180,12 @@ function getAllMoviesReleasedAtOrBeforeYear() {}
* checkMinMetascores(movies, 90));
* //> false
*/
function checkMinMetascores() {}
function checkMinMetascores(movies, metascore) {
if (movies.length === 0){
throw ('Error')
}
return movies.every(movie => movie.metascore === metascore)
}

/**
* getRottenTomatoesScoreByMovie()
Expand All @@ -160,7 +211,23 @@ function checkMinMetascores() {}
{ "James and the Giant Peach": "91%" },
];
*/
function getRottenTomatoesScoreByMovie() {}
function getRottenTomatoesScoreByMovie(movies) {
if (movies.length === 0) {
throw "Error";
}

let movieArr = movies.map((movie) => {
let key = movie.ratings.find((theRatings) => {
if (theRatings.source === "Rotten Tomatoes") {
return theRatings;
}
});

return ({ [movie.title]: key.value });
});

return movieArr;
}

// Do not change anything below this line.
module.exports = {
Expand Down