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

Done #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Done #20

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
66 changes: 59 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ const exampleMovies = require("./movies");
"James and the Giant Peach",
];
*/
function getAllMovieTitles() {}
function getAllMovieTitles(movies) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}
return movies.map((movie) => { // using .map with arrow function to itterate through all movies
return movie.title // and return the movie titles
})
}

/**
* checkIfAnyMovieHasRating()
Expand All @@ -50,7 +57,11 @@ function getAllMovieTitles() {}
* checkIfAnyMovieHasRating(movies, "R");
* //> false
*/
function checkIfAnyMovieHasRating() {}
function checkIfAnyMovieHasRating(movies, rating = "G") { // Default peramater for rating set to G
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
} return movies.some((movie) => movie.rated === rating) // Using .some, with the arrow fuction, itterates through movies until it finds the first the first truthy, then returns boolean depending on if there are any films that are rated. If non are rated then it defauts to G as the defaut perameter.
}

/**
* findById()
Expand All @@ -68,7 +79,13 @@ function checkIfAnyMovieHasRating() {}
// Toy Story 4
};
*/
function findById() {}
function findById(movies, ID) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}
let searchID = movies.find((movie) => movie.imdbID === ID) // using .find with arror function, itterates through the movies array to see if a matching ID is found
return searchID || null // If a match is found, it returns the first element found, otherwise returns null
}

/**
* filterByGenre()
Expand All @@ -92,7 +109,14 @@ function findById() {}
* filterByGenre(movies, "Horror")
* //> []
*/
function filterByGenre() {}
function filterByGenre(movies, genre) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}
return movies.filter((movie) => { // Using .filter with arrow function to itterate through the movies to create a new array of movie objects that have a matching genre
return movie.genre.toLowerCase().includes(genre.toLowerCase()); // Setting all genre values to lower case and returning matching genre movies
})
}

/**
* getAllMoviesReleasedAtOrBeforeYear()
Expand All @@ -118,7 +142,15 @@ function filterByGenre() {}
}
];
*/
function getAllMoviesReleasedAtOrBeforeYear() {}
function getAllMoviesReleasedAtOrBeforeYear(movies, year) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}
return movies.filter((movie) => { //Using .filter with arrow function, itterate through movie objects to create a new array, filtering out ones with correct year
let yearOfMovie = movie.released.split(" "); // create variable to hold the split released year string so we can obtain just the year
return yearOfMovie[2] <= year; // using the second index as the year, returning movies that years are less or equal to searched year.
})
}

/**
* checkMinMetascores()
Expand All @@ -134,7 +166,14 @@ function getAllMoviesReleasedAtOrBeforeYear() {}
* checkMinMetascores(movies, 90));
* //> false
*/
function checkMinMetascores() {}
function checkMinMetascores(movies, metascore) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}
return movies.every((movie) => { // using .every with arrow function to itterate through movies objects to givr true/false
return movie.metascore >= metascore; // returns true/false depending on if all movies have a minimum metascore
})
}

/**
* getRottenTomatoesScoreByMovie()
Expand All @@ -160,7 +199,20 @@ function checkMinMetascores() {}
{ "James and the Giant Peach": "91%" },
];
*/
function getRottenTomatoesScoreByMovie() {}
function getRottenTomatoesScoreByMovie(movies) {
if (!movies.length) { // If the movies array has no length...
throw "No movies inputted" // Then throw this error
}

return movies.map((movie) => { // using .map with arrow function to itterate through movies
newMovieObj = {} // making new movie object to return collected movie objects
let rotRating = movie.ratings.find((rating) => // getting to the rating and storing in rotRating variable using .find...if the following is true
rating.source === "Rotten Tomatoes") // Checking to see that rating = rot toms.

newMovieObj[movie.title] = rotRating.value // storing the key value pairs
return newMovieObj // returning all movies with rotten values
})
}

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