Source:AI & Agents — practice tasks — An exercise written for the study programme, not a confirmed interview task.
Not run automatically — compare with the checklist
1
2
3
4
5
6
7
8
9
10
11
// Deliberately faulty starter for review. Do NOT run against a real service.const seen=new Set<string>();
exportasyncfunctionconsume(messages:{id:string;amount:number}[], api:{pay:(amount:number)=>Promise<void>}) {
messages.forEach(async message=>{
if(seen.has(message.id))return;
seen.add(message.id);
try {await api.pay(message.amount);}
catch(error){console.log('ignored',error);}
});
return {success:true};
}
Tab indents · Esc, then Tab, leaves the editor · Your code is saved in this browser.
Hints
Stuck? Hints go from gentle to specific.
Reference solution
Give it a real try first — the solution is most useful after you've struggled a bit.