Untitled
// imperative const watchStatuses = users.reduce( (acc: Record<string, WatchStatus>, user: RawUser) => { const watchStatus = watchlist .slice() .reverse() .find( (watchnotice) => watchnotice.movieId === movie.movieId && watchnotice.userId === user.userId )?.status || WatchStatus.blank; acc[user.username] = watchStatus; return acc; }, {} ); //declarative const watchStatuse2 = Object.fromEntries(users.map(user => [ user.username, watchlist .slice() .reverse() .find( (watchnotice) => watchnotice.movieId === movie.movieId && watchnotice.userId === user.userId )?.status || WatchStatus.blank, ]));
Leave a Comment