diff --git a/index.js b/index.js index f184566..630414f 100644 --- a/index.js +++ b/index.js @@ -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() * ----------------------------- @@ -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() @@ -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() @@ -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() * ----------------------------- @@ -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() @@ -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() @@ -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 = { diff --git a/package-lock.json b/package-lock.json index 588a9f2..5874a04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1207,13 +1207,19 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001312", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz", - "integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "version": "1.0.30001434", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001434.tgz", + "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + } + ] }, "node_modules/chalk": { "version": "4.1.2", @@ -4583,9 +4589,9 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" }, "caniuse-lite": { - "version": "1.0.30001312", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz", - "integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==" + "version": "1.0.30001434", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001434.tgz", + "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==" }, "chalk": { "version": "4.1.2",