← Back to problems
Frontend: Promise.all Polyfill (Order + Fail-Fast)
MediumTypeScriptDescription
> This problem is paper-only - see explanation for the canonical JS solution. The auto-grader validates a synchronous model of the resolution + ordering + fail-fast logic.
Implement `promiseAll` semantics over a synchronous array of `{ kind: "resolve" | "reject", value }` "promise stubs". Return `{ status, value }` where:
- If any stub is "reject", `status: "rejected"` and `value` = the *first reject in input order*.
- Otherwise `status: "fulfilled"` and `value` = an array of resolved values in input order.
- Empty input -> `{ status: "fulfilled", value: [] }`.
**For the auto-grader:** implement `promiseAllModel(stubs)`.
Example 1
Input: stubs = [{kind:"resolve",value:1},{kind:"resolve",value:2}]
Output: {status:"fulfilled",value:[1,2]}
Example 2
Input: stubs = [{kind:"resolve",value:1},{kind:"reject",value:"boom"},{kind:"reject",value:"never"}]
Output: {status:"rejected",value:"boom"}
Explanation: First reject wins.
Example 3
Input: stubs = []
Output: {status:"fulfilled",value:[]}
Constraints
- 0 <= stubs.length <= 1000
Loading editor...