Concurrent with Promise.all()
Write a JavaScript function that takes an array of numbers, creates a delayed doubling Promise for each, and uses Promise.all() to wait for all of them to resolve, returning the array of doubled values.
Promise.all() is a static method that takes an iterable of Promises and returns a single Promise that resolves when all input Promises have resolved. The resolved value is an array of the individual results in the same order as the input. If any Promise rejects, Promise.all() immediately rejects with that error.
Unlike sequential .then() chaining where operations run one after another, Promise.all() runs all Promises concurrently. This is essential for performance when you have multiple independent async operations. The concurrency is not parallelism — JavaScript remains single-threaded, but I/O operations can overlap.
Time complexity is O(n) for creating n promises. The total wall-clock time is determined by the slowest promise, not the sum of all. The operations run concurrently, not sequentially. Space complexity is O(n) for the results array.
Edge cases include empty array (Promise.all resolves immediately with []), single promise, mixed fast and slow operations, and ensuring the results maintain input order.
Example Input & Output
Empty array
Larger numbers
Double all numbers
Mixed with zero
Single element
Algorithm Flow

Solution Approach
Best Answers
function delayedDouble(x) {
return Promise.resolve(x * 2);
}
function solution(nums) {
var promises = nums.map(function(x) {
return delayedDouble(x);
});
return Promise.all(promises);
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
