Command Palette

Search for a command to run...

Hectal
Phase 15: Patterns, Security and Interviews
JavaScript · Exercise 4 of 6 PreviousNext
Advanced

Interview classics: Promise.all and debounce

Write the two most-asked async functions from Topic 15.7, without using Promise.all, allSettled, race or any inside them.

1. promiseAll(iterable) returns a promise of all results in input order. It accepts any iterable (arrays, Sets) and plain values, resolves [] for empty input, and rejects with the first rejection.

2. debounce(fn, ms) returns a function that runs fn only after calls have stopped for ms milliseconds, with the latest arguments and the caller's this.

Then make the search box show Searching for: <text> in #out 200 ms after the user stops typing.

What Check tests

  1. promiseAll keeps input order and accepts plain values
  2. promiseAll([]) resolves to an empty array
  3. promiseAll rejects with the first error
  4. promiseAll accepts any iterable, such as a Set
  5. debounce runs once, with the latest arguments, after calls stop
  6. debounce keeps this
  7. The search box updates 200 ms after typing stops

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.