diff --git a/src/movies.ts b/src/movies.ts index 3dd9e0c..dd6c3e2 100644 --- a/src/movies.ts +++ b/src/movies.ts @@ -53,9 +53,7 @@ const movies: Movie[] = [ * hasKey({ title: "Inception", year: 2010 }, "director"); // => false */ function hasKey(obj: object, key: string): boolean { - // write your code here... - - return true; // replace true with what you see is fit + return Object.keys(obj).includes(key); } /** @@ -64,7 +62,9 @@ function hasKey(obj: object, key: string): boolean { * - Logs each movie title provided in the array of movies. */ function printMovieTitles(movies: Movie[]): void { - // write your code here... + movies.forEach((movie) => { + console.log(movie.title); + }); } /** @@ -81,7 +81,7 @@ function printMovieTitles(movies: Movie[]): void { function countMoviesByYear(movies: Movie[], year: number): number { // write your code here... - return -1; // replace -1 with what you see is fit + return movies.filter((movie) => movie.year === year).length; } /** @@ -108,9 +108,13 @@ function updateMovieGenre( title: string, newGenre: string ): Movie[] { - // write your code here... + const movieToUpdate = movies.find((movie) => movie.title === title); + + if (movieToUpdate) { + movieToUpdate.genre = newGenre; + } - return []; // replace empty array with what you see is fit + return movies; } export { Movie, hasKey, printMovieTitles, countMoviesByYear, updateMovieGenre };