From b5fb4e41ef3d2c9069b465c7be45d8147e7c4e8b Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 18:58:05 -0500 Subject: [PATCH 1/8] =?UTF-8?q?=E2=80=9C9-4-mid-module-two=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f184566..58603f5 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,12 @@ const exampleMovies = require("./movies"); "James and the Giant Peach", ]; */ -function getAllMovieTitles() {} +function getAllMovieTitles(movies) { + if (movies.length === 0) { + throw ('Error') + } + return movies.map(movie => movie.title) +} /** * checkIfAnyMovieHasRating() From b3ac33925d37334f565d697d88fe2c79add5cd41 Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:00:34 -0500 Subject: [PATCH 2/8] =?UTF-8?q?=E2=80=9C9-4-mid-module-two=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 58603f5..8ffb11e 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,12 @@ function getAllMovieTitles(movies) { * checkIfAnyMovieHasRating(movies, "R"); * //> false */ -function checkIfAnyMovieHasRating() {} +function checkIfAnyMovieHasRating(movies, rating="G") { + if (movies.length === 0){ + throw ('Error') + } + return movies.some(movie => movie.raiting = "G") +} /** * findById() From f62c02eda26dfa6ad94b48c4cef26a16af9db388 Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:03:08 -0500 Subject: [PATCH 3/8] =?UTF-8?q?=E2=80=9C9-4-mid-module-two=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8ffb11e..93a744e 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,12 @@ function checkIfAnyMovieHasRating(movies, rating="G") { // Toy Story 4 }; */ -function findById() {} +function findById(movies, id) { + if (movies.length === 0){ + throw ("Error") + } + return movies.find(movie => movie.imbdID === id) +} /** * filterByGenre() From fa5dfdc7364e408db76c21c557d737dbe2b4f176 Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:38:03 -0500 Subject: [PATCH 4/8] =?UTF-8?q?=E2=80=9C9-4-mid-module-two=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 93a744e..9a9c605 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ const exampleMovies = require("./movies"); function getAllMovieTitles(movies) { if (movies.length === 0) { throw ('Error') - } + } return movies.map(movie => movie.title) } @@ -58,9 +58,12 @@ function getAllMovieTitles(movies) { function checkIfAnyMovieHasRating(movies, rating="G") { if (movies.length === 0){ throw ('Error') + } + let result = movies.some((movie) => { + return movie.rated === rating; + }); + return result } - return movies.some(movie => movie.raiting = "G") -} /** * findById() @@ -107,7 +110,12 @@ function findById(movies, id) { * filterByGenre(movies, "Horror") * //> [] */ -function filterByGenre() {} +function filterByGenre(movies , genre) { + if (movies.length === 0){ + throw ('Error') + } + return movies.filter(movie => movies.genre.includes(genre)) +} /** * getAllMoviesReleasedAtOrBeforeYear() @@ -133,7 +141,12 @@ function filterByGenre() {} } ]; */ -function getAllMoviesReleasedAtOrBeforeYear() {} +function getAllMoviesReleasedAtOrBeforeYear(movies, year) { + if (movies.length === 0) { + throw('Error') + } + return movies.filter(movie => movie.released.includes(year)) +} /** * checkMinMetascores() @@ -149,7 +162,12 @@ function getAllMoviesReleasedAtOrBeforeYear() {} * checkMinMetascores(movies, 90)); * //> false */ -function checkMinMetascores() {} +function checkMinMetascores(movies, metascore) { + if (movies.length === 0){ + throw ('Error') + } + return movies.every(movie => movie.metascore === metascore) +} /** * getRottenTomatoesScoreByMovie() From bb4d2d56da15463d3f9cf98c576105cbc323299d Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:39:08 -0500 Subject: [PATCH 5/8] =?UTF-8?q?=E2=80=9C9-4-mid-module-two=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9a9c605..b5b67b8 100644 --- a/index.js +++ b/index.js @@ -59,10 +59,10 @@ function checkIfAnyMovieHasRating(movies, rating="G") { if (movies.length === 0){ throw ('Error') } - let result = movies.some((movie) => { + let myRes = movies.some((movie) => { return movie.rated === rating; }); - return result + return myRes } /** From e851f8324e28a2f446729fec4d954119b97bf35c Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:46:39 -0500 Subject: [PATCH 6/8] 9-4-mid-module-two --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b5b67b8..6222136 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,16 @@ function findById(movies, id) { if (movies.length === 0){ throw ("Error") } - return movies.find(movie => movie.imbdID === id) + let movieId = movies.find((movie) => { + if (movie.imdbID === id){ + return movie; + } + }); + if (movieId === 0){ + return null; + } else { + return movieId; + } } /** @@ -114,7 +123,12 @@ function filterByGenre(movies , genre) { if (movies.length === 0){ throw ('Error') } - return movies.filter(movie => movies.genre.includes(genre)) + let genreOfMovie = movies.filter((movie) => { + if (movie.genre.toUpperCase().includes(genre.toUpperCase())) { + return movie; + } + }); + return genreOfMovie } /** From 216dd732093190536aed078d1e6fba01b5c3c4bd Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:49:19 -0500 Subject: [PATCH 7/8] 9-4-mid-module-two --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6222136..784d5f4 100644 --- a/index.js +++ b/index.js @@ -159,7 +159,11 @@ function getAllMoviesReleasedAtOrBeforeYear(movies, year) { if (movies.length === 0) { throw('Error') } - return movies.filter(movie => movie.released.includes(year)) + let moviesByYear = movies.filter((movie) => { + return movie.released.substring(movie.released.length - 4) <= year; + }); + + return moviesByYear; } /** From 148c27f22ebee45b4fe42ac91bea00b061fdeef6 Mon Sep 17 00:00:00 2001 From: AdrianBurke1 Date: Mon, 28 Nov 2022 19:56:41 -0500 Subject: [PATCH 8/8] 9-4-mid-module-two --- index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 784d5f4..8109c04 100644 --- a/index.js +++ b/index.js @@ -211,7 +211,23 @@ function checkMinMetascores(movies, metascore) { { "James and the Giant Peach": "91%" }, ]; */ -function getRottenTomatoesScoreByMovie() {} + function getRottenTomatoesScoreByMovie(movies) { + if (movies.length === 0) { + throw "Error"; + } + + let movieArr = movies.map((movie) => { + let key = movie.ratings.find((theRatings) => { + if (theRatings.source === "Rotten Tomatoes") { + return theRatings; + } + }); + + return ({ [movie.title]: key.value }); + }); + + return movieArr; + } // Do not change anything below this line. module.exports = {