{ "data": { "question": { "questionId": "2859", "questionFrontendId": "2723", "boundTopicId": null, "title": "Add Two Promises", "titleSlug": "add-two-promises", "content": "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.\n

 

\n

Example 1:

\n\n
\nInput: \npromise1 = new Promise(resolve => setTimeout(() => resolve(2), 20)), \npromise2 = new Promise(resolve => setTimeout(() => resolve(5), 60))\nOutput: 7\nExplanation: The two input promises resolve with the values of 2 and 5 respectively. The returned promise should resolve with a value of 2 + 5 = 7. The time the returned promise resolves is not judged for this problem.\n
\n\n

Example 2:

\n\n
\nInput: \npromise1 = new Promise(resolve => setTimeout(() => resolve(10), 50)), \npromise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30))\nOutput: -2\nExplanation: The two input promises resolve with the values of 10 and -12 respectively. The returned promise should resolve with a value of 10 + -12 = -2.\n
\n\n

 

\n

Constraints:

\n\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 184, "dislikes": 15, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "new Promise(resolve => setTimeout(() => resolve(2), 20))\nnew Promise(resolve => setTimeout(() => resolve(5), 60))\nnew Promise(resolve => setTimeout(() => resolve(10), 50))\nnew Promise(resolve => setTimeout(() => resolve(-12), 30))", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {Promise} promise1\n * @param {Promise} promise2\n * @return {Promise}\n */\nvar addTwoPromises = async function(promise1, promise2) {\n \n};\n\n/**\n * addTwoPromises(Promise.resolve(2), Promise.resolve(2))\n * .then(console.log); // 4\n */", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "type P = Promise\n\nasync function addTwoPromises(promise1: P, promise2: P): P {\n\t\n};\n\n/**\n * addTwoPromises(Promise.resolve(2), Promise.resolve(2))\n * .then(console.log); // 4\n */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"37.6K\", \"totalSubmission\": \"41.7K\", \"totalAcceptedRaw\": 37558, \"totalSubmissionRaw\": 41693, \"acRate\": \"90.1%\"}", "hints": [], "solution": { "id": "1960", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "new Promise(resolve => setTimeout(() => resolve(2), 20))\nnew Promise(resolve => setTimeout(() => resolve(5), 60))", "metaData": "{\n \"name\": \"addTwoPromises\",\n \"params\": [\n {\n \"name\": \"promise1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"promise2\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }