mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
63 lines
6.9 KiB
JSON
63 lines
6.9 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "2733",
|
||
"questionFrontendId": "2621",
|
||
"categoryTitle": "JavaScript",
|
||
"boundTopicId": 2222274,
|
||
"title": "Sleep",
|
||
"titleSlug": "sleep",
|
||
"content": "<p>Given a positive integer <code>millis</code>, write an asynchronous function that sleeps for <code>millis</code> milliseconds. It can resolve any value.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> millis = 100\n<strong>Output:</strong> 100\n<strong>Explanation:</strong> It should return a promise that resolves after 100ms.\nlet t = Date.now();\nsleep(100).then(() => {\n console.log(Date.now() - t); // 100\n});\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> millis = 200\n<strong>Output:</strong> 200\n<strong>Explanation:</strong> It should return a promise that resolves after 200ms.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= millis <= 1000</code></li>\n</ul>\n",
|
||
"translatedTitle": "睡眠函数",
|
||
"translatedContent": "<p>请你编写一个异步函数,它接收一个正整数参数 <code>millis</code> ,并休眠 <code>millis</code> 毫秒。要求此函数可以解析任何值。</p>\n\n<p> </p>\n\n<p><b>示例 1:</b></p>\n\n<pre>\n<b>输入:</b>millis = 100\n<b>输出:</b>100\n<b>解释:</b>\n在 100ms 后此异步函数执行完时返回一个 Promise 对象\nlet t = Date.now();\nsleep(100).then(() => {\n console.log(Date.now() - t); // 100\n});\n</pre>\n\n<p><b>示例 2:</b></p>\n\n<pre>\n<b>输入:</b>millis = 200\n<b>输出:</b>200\n<b>解释:</b>在 200ms 后函数执行完时返回一个 Promise 对象\n</pre>\n\n<p> </p>\n\n<p><b>提示:</b></p>\n\n<ul>\n\t<li><code>1 <= millis <= 1000</code></li>\n</ul>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 14,
|
||
"dislikes": 0,
|
||
"isLiked": null,
|
||
"similarQuestions": "[]",
|
||
"contributors": [],
|
||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
|
||
"topicTags": [],
|
||
"companyTagStats": null,
|
||
"codeSnippets": [
|
||
{
|
||
"lang": "JavaScript",
|
||
"langSlug": "javascript",
|
||
"code": "/**\n * @param {number} millis\n * @return {Promise}\n */\nasync function sleep(millis) {\n \n}\n\n/** \n * let t = Date.now()\n * sleep(100).then(() => console.log(Date.now() - t)) // 100\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "TypeScript",
|
||
"langSlug": "typescript",
|
||
"code": "async function sleep(millis: number): Promise<void> {\n \n}\n\n\n/** \n * let t = Date.now()\n * sleep(100).then(() => console.log(Date.now() - t)) // 100\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"11.8K\", \"totalSubmission\": \"14.2K\", \"totalAcceptedRaw\": 11775, \"totalSubmissionRaw\": 14235, \"acRate\": \"82.7%\"}",
|
||
"hints": [
|
||
"In Javascript, you can execute code after some delay with the setTimeout(fn, sleepTime) function.",
|
||
"An async function is defined as function which returns a Promise.",
|
||
"To create a Promise, you can code new Promise((resolve, reject) => {}). When you want the function to return a value, code resolve(value) inside the callback."
|
||
],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "100",
|
||
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"name\": \"millis\",\n \"type\": \"integer\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"manual\": true,\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ]\n}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [],
|
||
"enableRunCode": true,
|
||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "100\n200",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |