Add Two Promises - Problem
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.
Input & Output
Example 1 — Basic Addition
$
Input:
promise1 resolves to 2, promise2 resolves to 5
›
Output:
7
💡 Note:
Both promises resolve with numbers, and 2 + 5 = 7
Example 2 — Negative Numbers
$
Input:
promise1 resolves to -4, promise2 resolves to 9
›
Output:
5
💡 Note:
Adding negative and positive: -4 + 9 = 5
Example 3 — Both Negative
$
Input:
promise1 resolves to -3, promise2 resolves to -7
›
Output:
-10
💡 Note:
Both negative numbers: -3 + (-7) = -10
Constraints
- promise1 and promise2 will always resolve with numbers
- Numbers can be positive, negative, or zero
- The promises will not reject
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two promises that resolve to numbers
2
Process
Await both promises and get their values
3
Output
Return sum of the two resolved values
Key Takeaway
🎯 Key Insight: Use Promise.all for concurrent execution to optimize performance
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code