Middle
/** * Implement a function any that works like Promise.any(). * The function takes an array of promises (assumed non-empty) and returns a promise. * If any of the promises resolve (successfully), * then the returned promise resolves with that value. * If multiple promises succeed, * then the returned promise resolves * with the first successful value, regardless of the order in the array. * If all promises reject, * then the returned promise rejects with an AggregateError, * which groups all errors, considering the order of promises. * * AggregateError can be created as follows: * new AggregateError(errors, 'No Promise in any was resolved') */ function any(promises) { // your code here }
sobes.tech AI
Answer from AI
This implementation creates a new promise that resolves upon the first successful completion of any of the provided promises. If all promises are rejected, it returns an AggregateError with an array of errors in the order of the original array.