{ "data": { "question": { "questionId": "2733", "questionFrontendId": "2621", "boundTopicId": null, "title": "Sleep", "titleSlug": "sleep", "content": "
Given a positive integer millis
, write an asynchronous function that sleeps for millis
milliseconds. It can resolve any value.
\n
Example 1:
\n\n\nInput: millis = 100\nOutput: 100\nExplanation: 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\n\n
Example 2:
\n\n\nInput: millis = 200\nOutput: 200\nExplanation: It should return a promise that resolves after 200ms.\n\n\n
\n
Constraints:
\n\n1 <= millis <= 1000
Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES6 features.
lodash.js library is included by default.
\\r\\n\\r\\nFor 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
.
Your code is run with --harmony
flag, enabling new ES2022 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }