frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

43 - Promise.any - javascript

Open jsartisan opened this issue 2 months ago • 0 comments

index.js

export function promiseAny(promises) {
  const errors = [];

  return new Promise((resolve, reject) => {
    promises.forEach((promise) => {
      Promise.resolve(promise)
        .then(resolve)
        .catch((err) => {
          errors.push(err);

          if (errors.length === promises.length) {
            reject(new AggregateError(errors));
          }
        });
    });
  });
}

jsartisan avatar Sep 28 '25 09:09 jsartisan