diff --git a/src/movies.ts b/src/movies.ts index 3dd9e0c..d5d10e6 100644 --- a/src/movies.ts +++ b/src/movies.ts @@ -54,8 +54,7 @@ const movies: Movie[] = [ */ function hasKey(obj: object, key: string): boolean { // write your code here... - - return true; // replace true with what you see is fit + return obj.hasOwnProperty(key); // replace true with what you see is fit } /** @@ -65,6 +64,7 @@ function hasKey(obj: object, key: string): boolean { */ function printMovieTitles(movies: Movie[]): void { // write your code here... + movies.forEach((movie) => console.log(movie.title)); } /** @@ -80,8 +80,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; // replace -1 with what you see is fit } /** @@ -109,8 +108,10 @@ function updateMovieGenre( newGenre: string ): Movie[] { // write your code here... - - return []; // replace empty array with what you see is fit + movies.forEach((movie) => + movie.title === title ? (movie.genre = newGenre) : movie + ); + return movies; // replace empty array with what you see is fit } export { Movie, hasKey, printMovieTitles, countMoviesByYear, updateMovieGenre };