Skip to content
Open

done #18

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
22 changes: 17 additions & 5 deletions src/movies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 key in obj; // replace true with what you see is fit
}

/**
Expand All @@ -65,8 +65,10 @@ function hasKey(obj: object, key: string): boolean {
*/
function printMovieTitles(movies: Movie[]): void {
// write your code here...
movies.forEach((movie) => {
console.log(movie.title);
});
}

/**
* `countMoviesByYear` function that:
* - Accepts two parameters:
Expand All @@ -81,7 +83,13 @@ 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
let count = 0;
for (const movie of movies) {
if (movie.year === year) {
count++;
}
}
return count;
}

/**
Expand Down Expand Up @@ -110,7 +118,11 @@ function updateMovieGenre(
): Movie[] {
// write your code here...

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

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