AniUI Academy
easy+150 XPPractice

Map an array with async work in parallel

Loading a detail record for every row in a table is the canonical case: you want all the requests in flight at once, but the results lined up with the rows they came from.

Implement mapAsync(items, fn). Call fn(item, index) for every item — all of them started before any of them are awaited — and resolve with an array of the resolved values in the original index order, regardless of which finished first. An empty array resolves with an empty array. If any call rejects, reject with the reason of whichever rejected first.

What it has to do

  • Start every call before awaiting any of them.
  • Resolve with values in input order, not completion order.
  • Pass the item's index to fn as the second argument.
  • Resolve with [] for an empty input array.
  • Reject with the first rejection reason.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.