Execute Asynchronous Functions in Parallel
\n\n# Code\njavascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function (functions) {\n    return new P
\n\n# Code\n```javascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function (functions) {\n    return new Promise((resolve, reject) => {\n        let results = []\n        let count = 0\n\n        if (functions.length === 0) {\n            resolve(results)\n        }\n\n        for (let i = 0; i < functions.length; i++) {\n            functions[i]()\n                .then(result => {\n                    results[i] = result\n                    count++\n\n                    if (count === functions.length) {\n                        resolve(results)\n                    }\n                })\n                .catch(error => {\n                    reject(error)\n                })\n        }\n    })\n};\n\n\n/**\n * const promise = promiseAll([() => new Promise(res => res(42))])\n * promise.then(console.log); // [42]\n */\n```
['JavaScript']