Skip to content
SDETRole
SDETRole

Implement Promise.all

advanced Promises Challenge 15 of 18

Implement promiseAll(values), which behaves like Promise.all, without calling Promise.all (or allSettled, any or race).

Requirements

  • Return a Promise that resolves to an array of results in input order, whatever order the inputs settle in.
  • Accept plain (non-Promise) values as well as Promises.
  • Resolve an empty input to [].
  • Reject as soon as any input rejects, with that input’s error.

Expected output

await promiseAll([delay(30, 'a'), 'b', delay(10, 'c')]) → ['a', 'b', 'c'] await promiseAll([Promise.reject(new Error('x'))]) → rejects with Error('x')

Test cases (6)

  • ○preserves input order regardless of completion order
  • ○accepts plain values
  • ○resolves an empty array immediately
  • ○rejects with the first rejection
  • ○does not use the built-in Promise.all
  • ○handles undefined results without miscounting
solution.jsExecutes in your browser

Ctrl/⌘ + Enter to run tests · your code is saved in this browser

Results

Run the tests to see results here.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →