Implement Promise.any
MediumPromises & Async20 min4 tests
Implement your own version of Promise.any that resolves with the first fulfilled promise. If all promises reject, reject with an AggregateError.
Requirements
- Resolve as soon as any promise fulfills
- If ALL promises reject, reject with an array of all rejection reasons
- Handle non-promise values (treat as immediately resolved)
Example
promiseAny([Promise.reject('a'), Promise.resolve('b'), Promise.reject('c')]); // 'b'Hints (4)
- Return a new Promise.
- The first promise to resolve should resolve the outer promise.
- Track all rejections in an array.
- Only reject the outer promise when ALL inner promises have rejected.
Topics
- Promises & Async
Asked at
Meta · Netflix · Apple
