Language
Topic
Level

Spot the bug · TypeScript, Basics, Easy · 1 of 5
Time on this item: 0:00

Who can edit a document

The task given to the agent

Return whether user may edit doc. Owners and admins may; archived docs are admin-only; suspended users may edit nothing.

The code it wrote

One line is wrong, or none is.

Line 1: export interface User {
Line 2: id: string;
Line 3: role: "admin" | "member";
Line 4: suspended: boolean;
Line 5: }
Line 6, blank:
Line 7: export interface Doc {
Line 8: id: string;
Line 9: ownerId: string;
Line 10: archived: boolean;
Line 11: }
Line 12, blank:
Line 13: export function canEditDocument(user: User, doc: Doc): boolean {
Line 14: if (user.suspended) return false;
Line 15: if (user.role === "admin") return true;
Line 16: if (doc.archived) return false;
Line 17: return doc.ownerId !== user.id;
Line 18: }