Async & Promises
Implement Promise.any
mediumJS SpecificJS / TS3 tests
Problem Statement
Implement `Promise.any`, which takes an iterable of promises and returns a single promise that resolves as soon as any of the input promises resolves, with the value of the resolved promise. If all input promises reject, the returned promise rejects with an `AggregateError` containing an array of rejection reasons in the original order.
Examples
Example 1:
const p1 = Promise.reject('error1');
const p2 = Promise.resolve('success2');
myPromiseAny([p1, p2]).then(console.log); // 'success2'
Example 2:
const p1 = Promise.reject('err1');
const p2 = Promise.reject('err2');
myPromiseAny([p1, p2]).catch(e => console.log(e.errors)); // ['err1', 'err2']JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
3 test cases. No second person needed.