Skip to content
GeeksSmith

Implement Promise.all Polyfill

Problem Statement

Implement `promiseAll(iterable)` which returns a Promise that resolves when all input promises have resolved (preserving input order) or rejects as soon as the first promise rejects.

Target Complexity

Time:

O(N) parallel execution

Space:

O(N) results array storage

Interview Talking Points:
  • Why `results[index] = val` is critical instead of `results.push(val)` (asynchronous resolution order differs from input order).
  • Why `Promise.resolve(item)` is necessary to wrap non-promise primitive inputs.
Solution Editor (JavaScript)
Ready to run
Test Results
Preserves output order despite different resolution delays
Test #1
Rejects immediately on first error
Test #2