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

9-4-Mid-Module-Two-Assessment Finito #21

Open
wants to merge 8 commits 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
2 changes: 1 addition & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe("getAllMoviesReleasedAtOrBeforeYear()", () => {
});
});

describe("getRottenTomatoesScoreByMovie()", () => {
describe.only("getRottenTomatoesScoreByMovie()", () => {
test("should use the `.map()` method", () => {
const text = getRottenTomatoesScoreByMovie.toString();
expect(text).toMatch(/\.map\(.*\)/s);
Expand Down
86 changes: 78 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const exampleMovies = require("./movies");
// Do not change the line above.

/**
* getAllMovieTitles()
* getAllMovieTitles()
* -----------------------------
* Returns all of titles from an array of movies. If the inputted `movies` array is empty, throw an error with a message.
* @param {Object[]} movies - An array of movies. See the `movies.js` file for an example of this array.
Expand All @@ -30,7 +30,15 @@ const exampleMovies = require("./movies");
"James and the Giant Peach",
];
*/
function getAllMovieTitles() {}
function getAllMovieTitles(movies) {
// loop thru entire movie titles array
// throw error if movies [] empty

if(movies.length === 0) {
throw 'Error. There are no movies listed.';
}
return movies.map((movie) => movie.title)
}

/**
* checkIfAnyMovieHasRating()
Expand All @@ -50,7 +58,21 @@ function getAllMovieTitles() {}
* checkIfAnyMovieHasRating(movies, "R");
* //> false
*/
function checkIfAnyMovieHasRating() {}
function checkIfAnyMovieHasRating(movies, rated = 'G') {
// should use the `.some()` method
// ✕ should throw an error if there are no movies
// ✕ should return `true` if any movie in the list has the given rating
// ✕ should return `false` if any movie in the list has the given rating
// ✕ should dynamically change depending on the movies inputted
// ✕ if no rating is passed, the default should be 'G'

if(movies.length === 0) {
throw 'There are no movies listed.';
}
let rating = movies.some((movie) => { return movie.rated === rated }
);
return rating;
}

/**
* findById()
Expand All @@ -68,7 +90,18 @@ function checkIfAnyMovieHasRating() {}
// Toy Story 4
};
*/
function findById() {}
function findById(movies, id) {
// let findThatMovie = movies.find(movie =>{
// return findThatMovie.imdbID === id
// })
// return findThatMovie === 0 ? null : findingNemo;

if(!movies.length)
throw 'Error. No movies found!';

let findThatMovie = movies.find((movie) => movie.imdbID === id);
return !findThatMovie ? null : findThatMovie;
}

/**
* filterByGenre()
Expand All @@ -92,7 +125,16 @@ function findById() {}
* filterByGenre(movies, "Horror")
* //> []
*/
function filterByGenre() {}
function filterByGenre(movies, genre) {
// try to LowerCase()
// loop, throw
if(!movies.length) {
throw "For the millionth time, there are no movies listed!."
};
return movies.filter((movie) => movie.genre
.toLowerCase().includes
(genre.toLowerCase()));
}

/**
* getAllMoviesReleasedAtOrBeforeYear()
Expand All @@ -118,7 +160,14 @@ function filterByGenre() {}
}
];
*/
function getAllMoviesReleasedAtOrBeforeYear() {}
function getAllMoviesReleasedAtOrBeforeYear(movies, year) {
// need additonal method to filter start and end.
if(!movies.length)
throw 'Error. No movies are available!';
return movies.filter( movie =>
movie.released
.slice(-5) <= year)
}

/**
* checkMinMetascores()
Expand All @@ -134,7 +183,14 @@ function getAllMoviesReleasedAtOrBeforeYear() {}
* checkMinMetascores(movies, 90));
* //> false
*/
function checkMinMetascores() {}
function checkMinMetascores(movies, minmetascore) {
// throw error if array empty
// check every movie metascore if > min score
if(!movies.length)
throw 'Error. Again, no movies!';

return movies.every(({ metascore }) => metascore > minmetascore);
}

/**
* getRottenTomatoesScoreByMovie()
Expand All @@ -160,7 +216,21 @@ function checkMinMetascores() {}
{ "James and the Giant Peach": "91%" },
];
*/
function getRottenTomatoesScoreByMovie() {}
function getRottenTomatoesScoreByMovie(movies) {
// throw error if array empty
// loop thru each movie - .find() movie title = Rotten Tomatoes, set to variable
// assign movie title, Rotten Tomatoes, return

if(!movies.length)
throw 'Error. Again, no more movies darn it!';

return movies.map((movie) => {
let getRottenTomatoesScore = movie.ratings.find((movie) =>
movie.source === 'Rotten Tomatoes');

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

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