Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/movies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const movies: Movie[] = [
* hasKey({ title: "Inception", year: 2010 }, "director"); // => false
*/
function hasKey(obj: object, key: string): boolean {
// write your code here...
return key in obj;

return true; // replace true with what you see is fit
// replace true with what you see is fit
}

/**
Expand All @@ -64,7 +64,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);
});
}

/**
Expand All @@ -79,9 +81,9 @@ function printMovieTitles(movies: Movie[]): void {
* countMoviesByYear(movies, 2025); // => 0
*/
function countMoviesByYear(movies: Movie[], year: number): number {
// write your code here...
return movies.filter((movie) => movie.year === year).length;

return -1; // replace -1 with what you see is fit
// replace -1 with what you see is fit
}

/**
Expand All @@ -108,9 +110,12 @@ function updateMovieGenre(
title: string,
newGenre: string
): Movie[] {
// write your code here...

return []; // replace empty array with what you see is fit
movies.forEach((movie) => {
if (movie.title === title) {
movie.genre = newGenre;
}
});
return movies;
}

export { Movie, hasKey, printMovieTitles, countMoviesByYear, updateMovieGenre };