iT邦幫忙

2023 iThome 鐵人賽

DAY 13
0
Software Development

LELECOCODE 每一天系列 第 13

Day 13 : Leetcode 小挑戰,30 Days of JavaScript

  • 分享至 

  • xImage
  •  

Day 13: Sleep

Given a positive integer millis, write an asynchronous function that sleeps for millis milliseconds. It can resolve any value.

async function sleep(millis) {
    
}

Example 1:
Input: millis = 100
Output: 100
Explanation: It should return a promise that resolves after 100ms.
let t = Date.now();
sleep(100).then(() => {
console.log(Date.now() - t); // 100
});

Example 2:
Input: millis = 200
Output: 200
Explanation: It should return a promise that resolves after 200ms.


async function sleep(millis) {
    return new Promise((resolve)=>{
        setTimeout(resolve, millis)
        })
}

上一篇
Day 12 : Leetcode 小挑戰,30 Days of JavaScript
下一篇
Day 14 : Leetcode 小挑戰,30 Days of JavaScript
系列文
LELECOCODE 每一天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言