Question presented to candidate: "Build a job board on top of the Hacker News API. One endpoint gives you the ids of the latest job posts; another gives you the details for a single id. Show the first six jobs with their title (linking to the posting when there is a URL), the poster and the date, and a Load more button that fetches the next six. You will not have network access in this exercise, so simulate the two endpoints in the file and say so."
Requirements:
- Simulate
jobstories.json(an array of ids, newest first) anditem/<id>.json(one job:id,by,timein unix seconds,title, optionalurl) withsetTimeoutdelays, including different delays per item so responses arrive out of order. - On load: fetch the ids once, then the details of the first six in parallel.
- "Load more jobs" fetches the next six; while loading it reads "Loading…" and is disabled, and a second click does nothing; it disappears when everything is loaded.
- Each card: the title as a link (
target="_blank"withrel="noopener noreferrer") when there is a URL, plain text otherwise, plus "By author · date" using a<time>element. - A failed request shows an alert with a Retry button that retries exactly what failed.
- Cards stay in id order no matter which request answers first.
What a strong answer should cover:
- The two-step data flow: ids first (cheap, one request), then details per page with
Promise.all, and whyPromise.allkeeps results in request order. - Loading, idle and error as explicit states, and guarding against double clicks and duplicate pages.
- Cleanup so a request that finishes after unmount (or after the React StrictMode double mount in development) does not set state.
- Converting unix seconds to milliseconds and formatting dates with
Intl.DateTimeFormat. - Trade-offs:
Promise.allfails the whole page if one item fails (versusPromise.allSettled), and when infinite scroll would replace the button.
Clarifying questions expected:
- "Should a single failed job hide the whole page, or should the rest still show?"
- "Is a Load more button fine, or do you want infinite scroll?"
- "How should a job without a URL behave?"
Code / implementation expected: Yes. A working page in React, Vue or Angular over an in-file simulated API, with loading, error and retry states.