Back to all solutions
#2723 - Add Two Promises
Problem Description
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
/**
* @param {Promise} promise1
* @param {Promise} promise2
* @return {Promise}
*/
var addTwoPromises = async function(promise1, promise2) {
return Promise.all([promise1, promise2]).then(([a, b]) => a + b);
};