File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -36,18 +36,6 @@ pnpm test
3636pnpm test:problem 2618
3737```
3838
39- ### 4. Development CLI
40-
41- ``` bash
42- pnpm dev
43- ```
44-
45- This starts ` src/main.ts ` , which accepts a problem number:
46-
47- ``` bash
48- pnpm dev 2618
49- ```
50-
5139---
5240
5341## 🤝 Contributing
Original file line number Diff line number Diff line change 1+ // * Title
2+ // 2621. Sleep
3+
4+ // * Concepts Asynchronous Programming, Promises, setTimeout
5+
6+ // * Description
7+ /**
8+ * Given a positive integer millis, write an asynchronous function that sleeps
9+ for millis milliseconds. It can resolve any value.
10+
11+ Note that minor deviation from millis in the actual sleep duration is
12+ acceptable.
13+ */
14+
15+ // * Hints
16+ /**
17+ * 1. In Javascript, you can execute code after some delay with the
18+ * setTimeout(fn, sleepTime) function.
19+ * 2. An async function is defined as function which returns a Promise.
20+ * 3. To create a Promise, you can code new Promise((resolve, reject) => {}).
21+ * When you want the function to return a value, code resolve(value) inside
22+ * the callback.
23+ */
24+
25+ // * Link to the problem: https://leetcode.com/problems/sleep/description
26+
27+ // * Solution
28+ export type SleepFunction = ( millis : number ) => Promise < void > ;
29+
30+ async function sleep ( millis : number ) : Promise < void > {
31+ return new Promise ( resolve => setTimeout ( resolve , millis ) ) ;
32+ }
33+
34+ // * Export the function
35+ export { sleep } ;
You can’t perform that action at this time.
0 commit comments