Implement a function promiseAny(promises) that behaves like Promise.any() but accepts an array instead of an iterable.
errors property is an array of rejection reasons (in the same order as the input array).errors is an empty array.Promise.resolve(value).Examples
const p0 = Promise.resolve(42); const p1 = new Promise((resolve) => setTimeout(() => resolve(21), 100)); await promiseAny([p0, p1]); // 42 const p0 = new Promise((resolve) => setTimeout(() => resolve(42), 100)); const p1 = new Promise((_, reject) => setTimeout(() => reject('Err!'), 50)); await promiseAny([p0, p1]); // 42 // If all reject: const p0 = new Promise((_, reject) => setTimeout(() => reject(42), 50)); const p1 = new Promise((_, reject) => setTimeout(() => reject('Err!'), 10)); try { await promiseAny([p0, p1]); } catch (e) { // e.errors should be [42, 'Err!'] (errors in input order) }
JavaScript Function
No test results yet
Click "Run" to execute tests