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

Joseph Rodriguez's 9-4-mid-module-two #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
58 changes: 50 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ const exampleMovies = require("./movies");
"James and the Giant Peach",
];
*/
function getAllMovieTitles() {}

getAllMovieTitles = (movies) => {
if (movies.length === 0) {
throw "error"
} else {
return movies.map(el => el.title)
}
}
/**
* checkIfAnyMovieHasRating()
* -----------------------------
Expand All @@ -50,7 +55,12 @@ function getAllMovieTitles() {}
* checkIfAnyMovieHasRating(movies, "R");
* //> false
*/
function checkIfAnyMovieHasRating() {}
checkIfAnyMovieHasRating = (movies, rating = "G") => {
if (movies.length === 0) {
throw "error"
}
return movies.some(el => el.rated === rating)
}

/**
* findById()
Expand All @@ -68,7 +78,14 @@ function checkIfAnyMovieHasRating() {}
// Toy Story 4
};
*/
function findById() {}
findById = (movies, id) => {
if (movies.length === 0) {
throw "error"
} else {
let movie = movies.find((el) => el.imdbID === id)
return (movie === undefined ? null : movie)
}
}

/**
* filterByGenre()
Expand All @@ -92,8 +109,14 @@ function findById() {}
* filterByGenre(movies, "Horror")
* //> []
*/
function filterByGenre() {}
filterByGenre = (movies, genre) => {
if (movies.length === 0) {
throw "error"
} else {
return movies.filter(el => el.genre.toLowerCase().includes(genre.toLowerCase()))

}
}
/**
* getAllMoviesReleasedAtOrBeforeYear()
* -----------------------------
Expand All @@ -118,7 +141,14 @@ function filterByGenre() {}
}
];
*/
function getAllMoviesReleasedAtOrBeforeYear() {}
getAllMoviesReleasedAtOrBeforeYear = (movies, year) => {
if (movies.length === 0) {
throw "error"
} else {
return movies.filter(el => el.released.split(" ")[2] <= year)
}

}

/**
* checkMinMetascores()
Expand All @@ -134,7 +164,13 @@ function getAllMoviesReleasedAtOrBeforeYear() {}
* checkMinMetascores(movies, 90));
* //> false
*/
function checkMinMetascores() {}
checkMinMetascores = (movies, metascore) => {
if (movies.length === 0) {
throw "error"
} else {
return movies.every(el => el.metascore > metascore)
}
}

/**
* getRottenTomatoesScoreByMovie()
Expand All @@ -160,7 +196,13 @@ function checkMinMetascores() {}
{ "James and the Giant Peach": "91%" },
];
*/
function getRottenTomatoesScoreByMovie() {}
function getRottenTomatoesScoreByMovie(movies) {
if (movies.length === 0) {
throw "error"
} else {
return movies.map(el => ({[el.title] : el.ratings.find(found => found.source === "Rotten Tomatoes").value}))
}
}

// Do not change anything below this line.
module.exports = {
Expand Down
26 changes: 16 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.