diff --git a/src/movies.ts b/src/movies.ts index 3dd9e0c..51fec52 100644 --- a/src/movies.ts +++ b/src/movies.ts @@ -53,10 +53,9 @@ 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 key in obj; // replace true with what you see is fit } +console.log(hasKey({ title: "Inception", year: 2010 }, "director")); /** * `printMovieTitles` function that: @@ -64,7 +63,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((a) => { + console.log(a.title); + }); } /** @@ -79,9 +80,14 @@ function printMovieTitles(movies: Movie[]): void { * countMoviesByYear(movies, 2025); // => 0 */ function countMoviesByYear(movies: Movie[], year: number): number { - // write your code here... + let count = 0; - return -1; // replace -1 with what you see is fit + movies.forEach((movie) => { + if (movie.year) { + count++; + } + }); + return count; } /** @@ -108,9 +114,12 @@ function updateMovieGenre( title: string, newGenre: string ): Movie[] { - // write your code here... + const fmov = movies.find((m) => m.title === title); + if (fmov) { + fmov.genre === newGenre; + } - return []; // replace empty array with what you see is fit + return movies; // replace empty array with what you see is fit } export { Movie, hasKey, printMovieTitles, countMoviesByYear, updateMovieGenre };