Review generated code that is subtly wrong
Medium30 minFree, no account
Clean, confident, well-commented, and broken in three places.
The question
A model produced the code below for "cache the result of an async function, deduplicating concurrent calls for the same key".
Find everything wrong with it. State how you would prove each one.
const cache = new Map();
export function memoizeAsync(fn, ttlMs = 60_000) {
return async function (key) {
const hit = cache.get(key);
if (hit && Date.now() - hit.at < ttlMs) {
return hit.value;
}
const value = await fn(key);
cache.set(key, { value, at: Date.now() });
return value;
};
}30:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.
Stuck?
0 of 3 hints takenThe worked solution
written by a person · not a gradeScore yourself
0 of 5 marked- Found that concurrent deduplication is entirely absent35
- Found the shared module-level cache15
- Found the error-path and unbounded-growth problems20
- Proposed storing the in-flight promise20
- Proved each defect by running something, not by re-prompting10
We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.
kept in this browser only