All challenges

TypeScript · hard

Stale paint

#33

Situation

Typeahead fires two searches, and the first one is slower. It finishes last and paints over the newer result, so Support sees stale names in screenshots. The most recently started search must own the display.

Objective

When two requests overlap, display the result from the request started last, even if the first finishes later. paintNames("Ada", "Bob") resolves to "Bob", and paintNames("Bob", "Ada") to "Ada".

The repo at start

workspace/
└── src/
    └── search.ts   (slow response paints over the latest)

Checks you will turn green

  • exports paintNames
  • the later query wins
  • it still wins with the names swapped

Concepts

async-awaitconcurrency

Play it in your terminal

With sharpen installed, this command opens exactly this challenge in your local arena:

sharpen 33

First time? The full install is right below.

How to play

  1. 1 Install Claude Code if you do not have it yet: claude.com/claude-code
  2. 2 Install sharpen from npm:
    npm install -g @juanwmedia/sharpen
  3. 3 Then launch it; the arena opens in your browser:
    sharpen 33
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 33
  5. 4 And to update when a new version ships:
    sharpen update