Last active
February 8, 2017 20:50
-
-
Save asduser/4d63d5ce49416b30eb67b8bda2759104 to your computer and use it in GitHub Desktop.
Different operations with Promise via Typescript/Javascript.
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
let divide = (num: number, divider: number = 10) => { | |
return new Promise<any>((resolve, reject) => { | |
resolve(num / divider); | |
}); | |
}; | |
let collection: number[] = [30, 40, 50]; | |
Promise.all(collection.map((n) => { | |
return divide(n); | |
})).then((res: number[]) => { | |
console.log(res); // output: [3, 4, 5] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment