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

mid module 2 #23

Open
wants to merge 3 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
90 changes: 83 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ const exampleMovies = require("./movies");
"James and the Giant Peach",
];
*/
function getAllMovieTitles() {}
function getAllMovieTitles(movies) {
if(movies.length === 0){
throw Error
}
let allTitles = movies.map((movie) => {
return movie.title
})
return allTitles
}



//use .map
// throw an error
// return aray of all titles
/**
* checkIfAnyMovieHasRating()
* -----------------------------
Expand All @@ -50,7 +63,19 @@ function getAllMovieTitles() {}
* checkIfAnyMovieHasRating(movies, "R");
* //> false
*/
function checkIfAnyMovieHasRating() {}
function checkIfAnyMovieHasRating(movies, rating = 'G') {
if(movies.length === 0) throw Error
let ratingCheck = movies.some((movie) => {
return movie.rated === rating
})
return ratingCheck
}



// use .some() & default param
// throws error
// returns boolean

/**
* findById()
Expand All @@ -68,8 +93,19 @@ function checkIfAnyMovieHasRating() {}
// Toy Story 4
};
*/
function findById() {}
function findById(movies, id) {
if(movies.length === 0) throw Error

let foundBy = movies.find((movie) => {
//if(movie.imdbID !== id) return null
return movie.imdbID === id
})
return foundBy
}


//use.find()
// throws error & null
/**
* filterByGenre()
* -----------------------------
Expand All @@ -92,7 +128,16 @@ function findById() {}
* filterByGenre(movies, "Horror")
* //> []
*/
function filterByGenre() {}
function filterByGenre(movies, genre) {
if(movies.length === 0) throw Error

let genreMatching = movies.filter((movie) => {
return movie.genre.includes(genre)
})
return genreMatching
}



/**
* getAllMoviesReleasedAtOrBeforeYear()
Expand All @@ -118,7 +163,13 @@ function filterByGenre() {}
}
];
*/
function getAllMoviesReleasedAtOrBeforeYear() {}
function getAllMoviesReleasedAtOrBeforeYear(movies, year) {
if(movies.length === 0) throw Error

let moviesBefore = movies.filter((movie) => movie.released.slice(7) <= year)

return moviesBefore
}

/**
* checkMinMetascores()
Expand All @@ -134,7 +185,14 @@ function getAllMoviesReleasedAtOrBeforeYear() {}
* checkMinMetascores(movies, 90));
* //> false
*/
function checkMinMetascores() {}
function checkMinMetascores(movies, metascore) {
if(movies.length === 0) return Error

let minMeta = movies.every((movie) => {
return movie.metascore >= metascore
})
return minMeta
}

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

let finalObject = movies.map((movie) => {


})
return finalObject

}






// use map() and find()
// throws error
// return an object {[movie.title] : }
// use to find() on rotten tomatoes
// Do not change anything below this line.
module.exports = {
getAllMovieTitles,
Expand Down