Skip to content
Closed

done #22

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
18 changes: 11 additions & 7 deletions src/movies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

/**
Expand All @@ -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;
}

/**
Expand All @@ -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 };