javascript · level 3 check

a polite request queue.

Time to ship a real tool. A pet rescue looks up its animals on Gwecode's practice server, at `https://api.example.com/pets/` followed by a name. Servers can be slow, busy or broken, and people type messy names. Your tool must cope with all of it, politely.

The names arrive one per `prompt` until it gives back `null`. Trim and lowercase each one, drop blanks and repeats with a Set, skip anything that is not letters (`/^[a-z]+$/.test(name)` checks that), then sort the rest. The queue never runs more than two requests at once, and records its peak.

Retry a server error, status 500 or above, up to two more times. Never retry a missing pet (404) or a garbled reply. `Promise.allSettled` lets one failure leave the others standing, so the report covers every pet, then a summary. Fill in each `____`, then run the tests.

Fill in every ____ then run the checks.
  1. 1 It looks up every pet, sorted, two at a timeuses: Promise.allSettled
  2. 2 It cleans up messy namesuses: Set
  3. 3 It retries a busy server, then gives upuses: custom errors
  4. 4 It never retries a missing petuses: throwing and catching
  5. 5 It survives a garbled replyuses: try...catch
  6. 6 It copes when there is nothing to look upuses: validating input

Take as long as you like and try as many times as you want.