Solution with Runtime 59 ms Beats 96.20%
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\n\nvar promiseAll = async function (functions) {\n    return new Promise((resolve, reject) => {\n        let count = 0;\n        let length = functions.length;\n        let results = [];\n        functions.forEach((func, i) => {\n            func().then(result => {\n                results[i] = result;\n                count++;\n                if (count == length) {\n                    resolve(results);\n                }\n            }).catch(error => {\n                reject(error);\n            });\n        });\n    });\n}\n\n/**\n * const promise = promiseAll([() => new Promise(res => res(42))])\n * promise.then(console.log); // [42]\n \n\n* solution with Promise.all()\n var promiseAll = function(functions){\n    return new Promise((resolve, reject) => {\n        const promises = functions.map(func => func());\n        Promise.all(promises)\n        .then(results => {\n            resolve(results);\n    })\n        .catch(error => {\n             reject(error);\n    });\n }\n}\n\nvar promiseAll = function(functions){\n    return new Promise((resolve, reject) => {\n        const promises = functions.map(func => func());\n        Promise.all(promises).then(result => {\n            resolve(result);\n        }).catch(error => {\n            reject(error);\n        })\n    })\n}\n\nvar promiseAll = function (functions){\n    return new Promise((resolve, reject) => {\n        let count = 0;\n        let length = functions.length;\n        let results = [];\n        functions.forEach((func, i) => {\n            func().then(result => {\n            results[i] = result;\n            count++;\n            if(count == length){\n                resolve(results);\n            }\n            }).catch(error => {\n                reject(error);\n            });\n        });\n    });\n}\n*/\n```
['JavaScript']