35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
export function allUsersDone(users: string[], doneUsers: string[]): boolean {
|
|
if (!Array.isArray(users) || users.length === 0 || !Array.isArray(doneUsers)) return false;
|
|
return users.every((name) => doneUsers.includes(name));
|
|
}
|
|
|
|
export function hasCompleteRatings(
|
|
movieTitles: string[],
|
|
votesForUser: Record<string, number> | null | undefined,
|
|
): boolean {
|
|
if (!Array.isArray(movieTitles) || !votesForUser || typeof votesForUser !== "object") return false;
|
|
for (const title of movieTitles) {
|
|
if (!Number.isInteger(votesForUser[title])) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export function collectCompleteRatings(
|
|
users: string[],
|
|
movieTitles: string[],
|
|
votes: Record<string, Record<string, number>>,
|
|
): Record<string, Record<string, number>> {
|
|
const output: Record<string, Record<string, number>> = {};
|
|
if (!Array.isArray(users) || !Array.isArray(movieTitles) || !votes || typeof votes !== "object") {
|
|
return output;
|
|
}
|
|
for (const name of users) {
|
|
if (!hasCompleteRatings(movieTitles, votes[name])) continue;
|
|
output[name] = {};
|
|
for (const title of movieTitles) {
|
|
output[name][title] = votes[name]![title]!;
|
|
}
|
|
}
|
|
return output;
|
|
}
|