Simple Solution with forEach and counter
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nGo through each functio
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGo through each function and keep track of function which are resolved, if all are resolved then return. If any rejects, reject the parent. \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        let data = new Array(functions.length);\n        let counter = 0;\n        functions.forEach((element, index) => {\n            const prom = element();\n            prom\n                .then((res) => {\n                    counter++;\n                    data[index] = res;\n                    if(counter === functions.length) {\n                        resolve(data);\n                    }\n                })\n                .catch((error) => {\n                    reject(error);\n                })\n        })\n        return data;\n    })\n};\n\n/**\n * const promise = promiseAll([() => new Promise(res => res(42))])\n * promise.then(console.log); // [42]\n */\n```
['JavaScript']