Skip to content

Instantly share code, notes, and snippets.

@lxhom
Created May 27, 2021 16:13
Show Gist options
  • Save lxhom/45e53c93323039068d3651a259b6d0b4 to your computer and use it in GitHub Desktop.
Save lxhom/45e53c93323039068d3651a259b6d0b4 to your computer and use it in GitHub Desktop.
just a simple demo for async in for loops
let { Toggle } = require("enquirer")
let main = async () => {
let questions = ["Are you 18 or older?", "Do you agree to your data being shared with 3rd parties?", "Do you" +
" accept our ToS?"];
let answers = {enabled: "Yes", disabled: "No"}
let values = []
for (let question of questions) {
values.push(await new Toggle({
message: question,
...answers
}).run())
}
console.log("Access", values.reduce((a, b) => a && b) ? "granted" : "denied")
}
// noinspection JSIgnoredPromiseFromCall
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment