mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
63 lines
5.8 KiB
JSON
63 lines
5.8 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "2859",
|
|
"questionFrontendId": "2723",
|
|
"boundTopicId": null,
|
|
"title": "Add Two Promises",
|
|
"titleSlug": "add-two-promises",
|
|
"content": "Given two promises <code>promise1</code> and <code>promise2</code>, return a new promise. <code>promise1</code> and <code>promise2</code> will both resolve with a number. The returned promise should resolve with the sum of the two numbers.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \npromise1 = new Promise(resolve => setTimeout(() => resolve(2), 20)), \npromise2 = new Promise(resolve => setTimeout(() => resolve(5), 60))\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> 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</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \npromise1 = new Promise(resolve => setTimeout(() => resolve(10), 50)), \npromise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30))\n<strong>Output:</strong> -2\n<strong>Explanation:</strong> 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</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>promise1</code> and <code>promise2</code> are promises that resolve with a number</li>\n</ul>\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<number>\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\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 5.1.6, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2022 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
|
"libraryUrl": null,
|
|
"adminUrl": null,
|
|
"challengeQuestion": null,
|
|
"__typename": "QuestionNode"
|
|
}
|
|
}
|
|
} |