#2723
Easy JavaScript Add two promises
91.8% acceptance
Mar 2, 2026
357
32
Given two promises promise1 and promise2, return a new promise. promise1 and promise2 will both resolve with a number. The returned promise should resolve with the sum of the two numbers.
Solution
TypeScript
Time O(1)
Space O(1)
type P = Promise<number>;
async function addTwoPromises(promise1: P, promise2: P): P {
const [a, b] = await Promise.all([promise1, promise2]);
return a + b;
}
/**
* addTwoPromises(Promise.resolve(2), Promise.resolve(2))
* .then(console.log); // 4
*/