Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ok = async () => true
- const fail = async () => false
- const run = async (list: Array<() => Promise<boolean>>): Promise<boolean> => {
- for(let i = 0; i < list.length; i++) {
- let result = await list[i]()
- if(result) { return true }
- } return false
- }
- //--------------------------------------------------
- // quiz: can you write this without async/await in
- // a clean and concise fashion?
- //--------------------------------------------------
- run([fail, fail, fail, fail, fail, ok]).then(result => {
- console.log(result)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement