Simple Code | Beat 70%
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 
# 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```\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function(functions) {\n  return new Promise((resolve, reject) => {\n    const results = [];\n    let resolvedCount = 0;\n    let rejected = false;\n\n    for (let i = 0; i < functions.length; i++) {\n      functions[i]()\n        .then(result => {\n          if (!rejected) {\n            results[i] = result;\n            resolvedCount++;\n\n            if (resolvedCount === functions.length) {\n              resolve(results);\n            }\n          }\n        })\n        .catch(error => {\n          if (!rejected) {\n            rejected = true;\n            reject(error);\n          }\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']