FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Promise AllSettled

25mins

Implement a function promiseAllSettled(promises) that accepts an array of promises (or values) and returns a promise that resolves when all of them have settled.

The returned promise should resolve to an array of objects representing the outcome of each input:

  • If a promise resolves, the object should be { status: 'fulfilled', value: result }.
  • If a promise rejects, the object should be { status: 'rejected', reason: error }.

Examples

const p1 = Promise.resolve(1); const p2 = Promise.reject('err'); const p3 = 3; await promiseAllSettled([p1, p2, p3]); // [ // { status: 'fulfilled', value: 1 }, // { status: 'rejected', reason: 'err' }, // { status: 'fulfilled', value: 3 } // ]

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests