Title: 2621. Sleep function

​​The source of the topic

        Leetcode topic, URL: 2621. Sleep function - LeetCode

Problem-solving ideas:

       Return the Promise object as required, and just sleep in the Promise object.

Problem-solving code:

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

/** 
 * let t = Date.now()
 * sleep(100).then(() => console.log(Date.now() - t)) // 100
 */
 
 

Summarize:

        No official solution.

        passed inexplicably.


Guess you like

Origin blog.csdn.net/2301_76145947/article/details/132638367