LeetCode solutions

2859. Add Two Promises

My accepted JavaScript solution to LeetCode problem 2859, Add Two Promises, running in 57ms.

  • Difficulty: Easy
  • JavaScript
  • Runtime 57ms
  • Memory 54.3MB

Read the problem on LeetCode View on GitHub

JavaScript

Accepted on LeetCode — runtime 57ms, memory 54.3MB, accepted 2025-12-31.

javascript
/**
 * @param {Promise} promise1
 * @param {Promise} promise2
 * @return {Promise}
 */
var addTwoPromises = async function(promise1, promise2) {
    const [val1, val2] = await Promise.all([promise1, promise2]);
    return val1 + val2;
};

/**
 * addTwoPromises(Promise.resolve(2), Promise.resolve(2))
 *   .then(console.log); // 4
 */

Source