Promise.all
Promise.all
Implement your own version of Promise.all that takes an array of promises and returns a single Promise.
Requirements:
- Return a Promise that resolves when all input promises resolve
- The resolved value should be an array of all resolved values in order
- If any promise rejects, immediately reject with that error
- Handle empty array (should resolve immediately with empty array)
Example:
const p1 = Promise.resolve(3);
const p2 = Promise.resolve(42);
const p3 = new Promise(resolve => setTimeout(() => resolve('foo'), 100));
promiseAll([p1, p2, p3]).then(values => {
console.log(values); // [3, 42, 'foo']
});
Examples:
Input 1:
{"nums":[1,2,3]}Output 1:
[1,2,3]Input 2:
{"nums":[]}Output 2:
[]Loading editor...
Run your code to see results
Click the Run button above