Loading problem…
Implement promiseAll — a utility that behaves like native Promise.all for iterables.
Async aggregation is frequently tested in interviews. If you can implement Promise.all correctly, you’ll recognize the same coordination patterns behind Promise.race, Promise.any, and Promise.allSettled.
then)[].// Example: Preserves index order (not completion order)
const slow = new Promise((r) => setTimeout(() => r("slow"), 20));
const fast = Promise.resolve("fast");
promiseAll([slow, fast]).then(value => {
console.log(value); // ["slow", "fast"]
});
// Example: Treat values / thenables as resolved inputs
promiseAll([1, { then: (r) => r(2) }, Promise.resolve(3)]).then(value => {
console.log(value); // [1, 2, 3]
});
// Example: Works with any iterable (Set example)
promiseAll(new Set([Promise.resolve(1), Promise.resolve(2)])).then(value => {
console.log(value); // [1, 2]
});
// Example: Rejects immediately on first rejection
promiseAll([
Promise.resolve(1),
Promise.reject("error"),
Promise.resolve(3)
]).catch(error => {
console.log(error); // "error"
});