Skip to content

Instantly share code, notes, and snippets.

@pieterbeulque
Created February 21, 2019 16:12
Show Gist options
  • Save pieterbeulque/b6f383a0b753ae669ad219282f1ee18f to your computer and use it in GitHub Desktop.
Save pieterbeulque/b6f383a0b753ae669ad219282f1ee18f to your computer and use it in GitHub Desktop.
const ask = async (question) => Promise.resolve('Answer ' + question);
const questions = [1, 2, 3];
const answers = await questions.reduce(async (accumulator, nextQuestion) => {
const allAnswers = await accumulator;
const answer = await ask(nextQuestion);
return Promise.resolve([...allAnswers, answer]);
}, Promise.resolve([]));
console.log(answers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment