From 38df7ae147762af073ff69624feb000983c6adb4 Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 18:49:23 -0500 Subject: [PATCH 1/8] getAllMovieTitles() finito --- __tests__/index.test.js | 2 +- index.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 3e05c4d..65634fe 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -11,7 +11,7 @@ const { const movies = require("../movies"); const alternative = require("./fixtures/alternative-movies"); -describe("getAllMovieTitles()", () => { +describe.only("getAllMovieTitles()", () => { test("should use the `.map()` method", () => { const text = getAllMovieTitles.toString(); expect(text).toMatch(/\.map\(.*\)/s); diff --git a/index.js b/index.js index f184566..e9115d3 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,14 @@ 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() From c6bacef3210572c99b403cb16a55f44767c274fa Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 18:58:05 -0500 Subject: [PATCH 2/8] checkIfAnyMovieHasRating finito --- __tests__/index.test.js | 4 ++-- index.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 65634fe..cd2e056 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -11,7 +11,7 @@ const { const movies = require("../movies"); const alternative = require("./fixtures/alternative-movies"); -describe.only("getAllMovieTitles()", () => { +describe("getAllMovieTitles()", () => { test("should use the `.map()` method", () => { const text = getAllMovieTitles.toString(); expect(text).toMatch(/\.map\(.*\)/s); @@ -43,7 +43,7 @@ describe.only("getAllMovieTitles()", () => { }); }); -describe("checkIfAnyMovieHasRating()", () => { +describe.only("checkIfAnyMovieHasRating()", () => { test("should use the `.some()` method", () => { const text = checkIfAnyMovieHasRating.toString(); expect(text).toMatch(/\.some\(.*\)/s); diff --git a/index.js b/index.js index e9115d3..afb5e8b 100644 --- a/index.js +++ b/index.js @@ -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. @@ -33,6 +33,7 @@ const exampleMovies = require("./movies"); 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.'; } @@ -57,7 +58,21 @@ function getAllMovieTitles(movies) { * 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() From 7434664713a844a43e276d4687f2a833d659782b Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 19:46:42 -0500 Subject: [PATCH 3/8] findById throw error fix --- __tests__/index.test.js | 4 ++-- index.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index cd2e056..24fc16b 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -43,7 +43,7 @@ describe("getAllMovieTitles()", () => { }); }); -describe.only("checkIfAnyMovieHasRating()", () => { +describe("checkIfAnyMovieHasRating()", () => { test("should use the `.some()` method", () => { const text = checkIfAnyMovieHasRating.toString(); expect(text).toMatch(/\.some\(.*\)/s); @@ -76,7 +76,7 @@ describe.only("checkIfAnyMovieHasRating()", () => { }); }); -describe("findById()", () => { +describe.only("findById()", () => { test("should use the `.find()` method", () => { const text = findById.toString(); expect(text).toMatch(/\.find\(.*\)/s); diff --git a/index.js b/index.js index afb5e8b..75f7d9e 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ function checkIfAnyMovieHasRating(movies, rated = 'G') { // ✕ 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.'; } @@ -90,7 +90,15 @@ function checkIfAnyMovieHasRating(movies, rated = 'G') { // Toy Story 4 }; */ -function findById() {} +function findById(movies, id) { +// let findThatMovie = movies.find(movie =>{ +// return findThatMovie.imdbID === id +// }) +// return findThatMovie === 0 ? null : findThatMovie; +id(movies.length) +let findThatMovie = movies.find((movie) => movie.imdbID === id); +return !findThatMovie ? null : findThatMovie; +} /** * filterByGenre() From d5c904c0413455bd0a44135608e4854f18de25ee Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 19:48:33 -0500 Subject: [PATCH 4/8] findbyID finito --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 75f7d9e..6e84046 100644 --- a/index.js +++ b/index.js @@ -94,10 +94,13 @@ function findById(movies, id) { // let findThatMovie = movies.find(movie =>{ // return findThatMovie.imdbID === id // }) -// return findThatMovie === 0 ? null : findThatMovie; -id(movies.length) +// 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; + return !findThatMovie ? null : findThatMovie; } /** From 87fc1fc052ad3426a0d69044f8cd4684a21ef588 Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 19:51:53 -0500 Subject: [PATCH 5/8] filterByGenre finito --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6e84046..a32ba85 100644 --- a/index.js +++ b/index.js @@ -125,7 +125,16 @@ let findThatMovie = movies.find((movie) => movie.imdbID === id); * 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() From 97a67932dc192d65934e19374e43b7e59c8ee58d Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 20:15:34 -0500 Subject: [PATCH 6/8] getAllMoviesReleasedAtOrBeforeYear finito --- __tests__/index.test.js | 4 ++-- index.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 24fc16b..287b7c7 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -76,7 +76,7 @@ describe("checkIfAnyMovieHasRating()", () => { }); }); -describe.only("findById()", () => { +describe("findById()", () => { test("should use the `.find()` method", () => { const text = findById.toString(); expect(text).toMatch(/\.find\(.*\)/s); @@ -204,7 +204,7 @@ describe("checkMinMetascores()", () => { }); }); -describe("getAllMoviesReleasedAtOrBeforeYear()", () => { +describe.only("getAllMoviesReleasedAtOrBeforeYear()", () => { test("should use the `.filter()` method", () => { const text = filterByGenre.toString(); expect(text).toMatch(/\.filter\(.*\)/s); diff --git a/index.js b/index.js index a32ba85..8e3a211 100644 --- a/index.js +++ b/index.js @@ -160,7 +160,14 @@ function filterByGenre(movies, genre) { } ]; */ -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() From 96d4a56bcc6694b23f11e640fb4fee8ee5899f28 Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 20:30:07 -0500 Subject: [PATCH 7/8] checkMinMetascores, rename param, destructure --- __tests__/index.test.js | 4 ++-- index.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 287b7c7..00c3044 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -181,7 +181,7 @@ describe("filterByGenre()", () => { }); }); -describe("checkMinMetascores()", () => { +describe.only("checkMinMetascores()", () => { test("should use the `.every()` method", () => { const text = checkMinMetascores.toString(); expect(text).toMatch(/\.every\(.*\)/s); @@ -204,7 +204,7 @@ describe("checkMinMetascores()", () => { }); }); -describe.only("getAllMoviesReleasedAtOrBeforeYear()", () => { +describe("getAllMoviesReleasedAtOrBeforeYear()", () => { test("should use the `.filter()` method", () => { const text = filterByGenre.toString(); expect(text).toMatch(/\.filter\(.*\)/s); diff --git a/index.js b/index.js index 8e3a211..c0519af 100644 --- a/index.js +++ b/index.js @@ -183,7 +183,14 @@ function getAllMoviesReleasedAtOrBeforeYear(movies, year) { * 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() From 3e2610dc5d65615926c631c14f2708fda8832303 Mon Sep 17 00:00:00 2001 From: shareekaepps Date: Mon, 28 Nov 2022 20:46:08 -0500 Subject: [PATCH 8/8] getRottenTomatoesScoreByMovie finito, return fixed --- __tests__/index.test.js | 4 ++-- index.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 00c3044..ee187d5 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -181,7 +181,7 @@ describe("filterByGenre()", () => { }); }); -describe.only("checkMinMetascores()", () => { +describe("checkMinMetascores()", () => { test("should use the `.every()` method", () => { const text = checkMinMetascores.toString(); expect(text).toMatch(/\.every\(.*\)/s); @@ -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); diff --git a/index.js b/index.js index c0519af..a3f714f 100644 --- a/index.js +++ b/index.js @@ -216,7 +216,21 @@ function checkMinMetascores(movies, minmetascore) { { "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 = {