A slow response replaces the results for a newer search. Fix the updater.
about 25 min · 7 required tests · graded in a remote sandbox
What is recorded: when you save, your Result page shows your code, which tests passed, how many times you ran the tests, how many versions you tried, the time from first run to save, and the largest jump in code between runs. Anyone with the link can see it. The suggested time is not enforced. Your browser also reports how many times you paste into the editor and the size of the largest paste, never the text. Those counts appear on the Result.
This Challenge takes about 25 min at a keyboard. It works on a phone, but a laptop is easier.
Press Esc, then Tab, to leave the editor.
⌘ / Ctrl + Enter runs the tests
Hiring developers? See how teams use this.
How it is graded
0/7
Try the contract
This is the behavior the tests check. It is not your code.
A support agent types ca and then cat in a customer search box. Results for cat appear first. When the older request finally returns, the list flips back to ca.
Fix the code in the editor. The caller creates one updater per search box with createSearchUpdater(search, publish) and calls the returned function with the raw input. search(query) returns a promise for an array of strings and can also throw synchronously. publish(state) updates the UI.
{ status: 'idle', query: '' } immediately and skip the search.{ status: 'loading', query } immediately and call search(query). Use the trimmed query in every state.{ status: 'ready', query, items }. An empty array is a successful result.{ status: 'error', query, message: 'Search failed' } if the invocation is still current.Reproduce it by starting ca, starting cat, resolving cat, and finally resolving ca. The final state should still show results for cat. The tests control when each promise settles. You can leave the network requests running.
Write a top-level function named createSearchUpdater. Do not use export or module.exports.
Optional: attach dispose() to the returned function. After disposal, pending completions and future calls must be silent, and future calls must not start a search.
Other Challenges
Hiring note
Send a candidate this Challenge. You get a Result with their code, the test results and questions to ask in the interview.
Send this Challenge