Junior — Senior
Creating a function that mimics Promise.allSettled
livecode
Task condition
It is necessary to implement the function allSettled(), which reproduces the behavior of the standard Promise.allSettled method.
function allSettled(inputs) {}
allSettled([
new Promise((resolve) => setTimeout(() => resolve(1), 1000)),
Promise.reject(2),
Promise.resolve(3),
]).then(console.log);
// [
// { "status": "fulfilled", "value": 1 },
// { "status": "rejected", "reason": 2 },
// { "status": "fulfilled", "value": 3 }
// ]
The function should accept an array of promises (or values compatible with promises) and return a new promise that resolves after all the passed promises have settled. The result should be an array of objects, each containing a status field with the value "fulfilled" or "rejected" and a corresponding value or reason field with the result or rejection reason.