Created
October 3, 2016 19:16
-
-
Save indatawetrust/47bc4a500a09cc8ce68813058fc0c698 to your computer and use it in GitHub Desktop.
async await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const upper = async function (n) { | |
const list = [] | |
for(let i of new Array(n+1).join('.').split('').map((a,b) => b+1)){ | |
list.push(await new Promise(res => { | |
if (list.length) | |
res(list.toString().split(',').pop()*2) | |
else | |
res(n) | |
})) | |
} | |
return list | |
} | |
upper(50).then(console.log) | |
/* | |
[50, 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800, 6553600, 13107200, 26214400, 52428800, 104857600, 209715200, 419430400, 838860800, 1677721600, 3355443200, 6710886400, 13421772800, 26843545600, 53687091200, 107374182400, 214748364800, 429496729600, 858993459200, 1717986918400, 3435973836800, 6871947673600, 13743895347200, 27487790694400, 54975581388800, 109951162777600, 219902325555200, 439804651110400, 879609302220800, 1759218604441600, 3518437208883200, 7036874417766400, 14073748835532800, 28147497671065600] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment