Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 969 Bytes

_2621. Sleep.md

File metadata and controls

48 lines (36 loc) · 969 Bytes

2621. Sleep

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 09, 2024

Last updated : July 09, 2024


Related Topics : N/A

Acceptance Rate : 87.42 %


Solutions

JavaScript

/**
 * @param {number} millis
 * @return {Promise}
 */
async function sleep(millis) {
    return new Promise(resolve => setTimeout(resolve, millis));
}

/** 
 * let t = Date.now()
 * sleep(100).then(() => console.log(Date.now() - t)) // 100
 */
async function sleep(millis) {
    return new Promise((resolve=millis, reject) => setTimeout(resolve, millis));
}