-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTwoPromises.js
More file actions
19 lines (16 loc) · 557 Bytes
/
Copy pathAddTwoPromises.js
File metadata and controls
19 lines (16 loc) · 557 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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.
/**
* @param {Promise} promise1
* @param {Promise} promise2
* @return {Promise}
*/
var addTwoPromises = async function(promise1, promise2) {
const [value1, value2] = await Promise.all([promise1, promise2]);
return value1 + value2;
};
/**
* addTwoPromises(Promise.resolve(2), Promise.resolve(2))
* .then(console.log); // 4
*/