diff --git a/solution/2600-2699/2621.Sleep/README.md b/solution/2600-2699/2621.Sleep/README.md index 2607dfdc0a1d6..b718f2a944108 100644 --- a/solution/2600-2699/2621.Sleep/README.md +++ b/solution/2600-2699/2621.Sleep/README.md @@ -70,6 +70,23 @@ async function sleep(millis: number): Promise { */ ``` +#### JavaScript + +```js +/** + * @param {number} millis + * @return {Promise} + */ +async function sleep(millis) { + return new Promise(r => setTimeout(r, millis)); +} + +/** + * let t = Date.now() + * sleep(100).then(() => console.log(Date.now() - t)) // 100 + */ +``` + diff --git a/solution/2600-2699/2621.Sleep/README_EN.md b/solution/2600-2699/2621.Sleep/README_EN.md index 4d33630e3513d..5f32460b81662 100644 --- a/solution/2600-2699/2621.Sleep/README_EN.md +++ b/solution/2600-2699/2621.Sleep/README_EN.md @@ -67,6 +67,23 @@ async function sleep(millis: number): Promise { */ ``` +#### JavaScript + +```js +/** + * @param {number} millis + * @return {Promise} + */ +async function sleep(millis) { + return new Promise(r => setTimeout(r, millis)); +} + +/** + * let t = Date.now() + * sleep(100).then(() => console.log(Date.now() - t)) // 100 + */ +``` + diff --git a/solution/2600-2699/2621.Sleep/Solution.js b/solution/2600-2699/2621.Sleep/Solution.js new file mode 100644 index 0000000000000..91bd9ae81b5a8 --- /dev/null +++ b/solution/2600-2699/2621.Sleep/Solution.js @@ -0,0 +1,12 @@ +/** + * @param {number} millis + * @return {Promise} + */ +async function sleep(millis) { + return new Promise(r => setTimeout(r, millis)); +} + +/** + * let t = Date.now() + * sleep(100).then(() => console.log(Date.now() - t)) // 100 + */