We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0052f94 commit 7d3a272Copy full SHA for 7d3a272
day19/leetcode2721.js
@@ -0,0 +1,33 @@
1
+// 2721. Execute Asynchronous Functions in Parallel
2
+// URL -> https://leetcode.com/problems/execute-asynchronous-functions-in-parallel/
3
+
4
+/**
5
+ * @param {Array<Function>} functions
6
+ * @return {Promise<any>}
7
+ */
8
+var promiseAll = function (functions) {
9
+ return new Promise((resolve, reject) => {
10
+ let res = [], count = 0;
11
12
+ for (let i = 0; i < functions.length; i++) {
13
+ functions[i]()
14
+ .then(result => {
15
+ res[i] = result;
16
+ count++;
17
18
+ if (count === functions.length) {
19
+ resolve(res);
20
+ }
21
+ })
22
+ .catch(error => {
23
+ reject(error);
24
+ });
25
26
27
28
+};
29
30
31
+ * const promise = promiseAll([() => new Promise(res => res(42))])
32
+ * promise.then(console.log); // [42]
33
0 commit comments