Untitled
unknown
javascript
10 months ago
669 B
4
Indexable
// 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,
]));Editor is loading...
Leave a Comment