-
-
Save xiaoxiangmoe/544e1db4ac9ea8e691673d98f52ba5a3 to your computer and use it in GitHub Desktop.
问题:用此API打印出从1到30的十进制转十六制的对应表(最好按顺序打印)
This file contains 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
// https://coolshell.cn/t.html | |
const scan = (xs, func, init) => | |
xs.reduce( | |
(accu, curr, i, arr) => [ | |
...accu, | |
func(accu[accu.length - 1], curr, i, arr), | |
], | |
[init], | |
); | |
scan( | |
Array.from({ length: 20 }).map( | |
(x, i) => new Promise(resolve => xss_rpc_call2(i, resolve)), | |
), | |
(prev, curr) => | |
Promise.all([prev, curr]).then(([xs, x]) => [...xs, x]), | |
Promise.resolve([]), | |
).forEach(x => x.then(console.log)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如果只需要最后再显示,改 scan 成 Promise.all 即可。
如果需要超时逻辑,添加一个 Promise.race 即可。