3 ms·
With async/await this can become: const reduceP = async (fn, identity, listP) => { const values = await Promise.all(listP) return values.reduce
by molf 9y ago
With async/await this can become:
const reduceP = async (fn, identity, listP) => {
const values = await Promise.all(listP)
return values.reduce(fn, identity)
}
The whole thing feels like a synthetic and overcomplicated example, though. In practice I'm sure I'd just write:
let total = 0
while (listP.length > 0) {
total += await listP.pop()
}
- megawatthours 9y agoThat code does the same thing as https://news.ycombinator.com/item?id=15302465 https://news.ycombinator.com/item?id=15302465 but not the same thing as the code in the article.