Skip to content

Raghad Alobaid #9

Open
rfo97 wants to merge 2 commits intoJoinCODED:mainfrom
rfo97:main
Open

Raghad Alobaid #9
rfo97 wants to merge 2 commits intoJoinCODED:mainfrom
rfo97:main

Conversation

@rfo97
Copy link

@rfo97 rfo97 commented Mar 11, 2025

No description provided.

counter++;
}
});
return counter; // replace -1 with what you see is fit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been a filter instead of a forEach:

function countMoviesByYear(movies: Movie[], year: number): number {
  return movies.filter((movie) => movie.year === year).length;
}

movies.forEach((movie) =>
movie.title === title ? (movie.genre = newGenre) : movie
);
return movies;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been solved using .find:

function updateMovieGenre(
  movies: Movie[],
  title: string,
  newGenre: string
): Movie[] {
  const movieToUpdate = movies.find((movie) => movie.title === title) // returns the movie or undefined
  if(movieToUpdate)
    movieToUpdate.genre = newGenre;
  return movies;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants