Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

分享 node 面试题

$
0
0

这题 es7 解法!

let sleep = [];

for (var i = 0; i < 5; i++) {
    ((j) => {
        sleep.push(new Promise(function (resolve, reject) {

            setTimeout(function () {
                console.log(new Date, j);
                resolve();
            }, j * 1000)
        }))
    })(i)
}
 // await只能使用在原生语法
(async () => {
    for (let item of sleep) {
        await item
    }
    console.log(new Date(), i);
})();

北京 某个公司Node.js 面试题 传送门


Viewing all articles
Browse latest Browse all 14821

Trending Articles