O(n) solution
Approach\n## promiseAll:\n - It accepts an array of functions (functions), where each function returns a promise.\n - We create a new promise that will resolve 
# Approach\n## promiseAll:\n - It accepts an array of functions (functions), where each function returns a promise.\n - We create a new promise that will resolve once all promises  from the functions are resolved, or reject as soon as any promise is rejected.\n - results is an array to store the resolved values in the correct order (based on the index of the input functions).\n - resolvedCount keeps track of how many promises have been resolved.\n - For each function in the array:\n   - We invoke the function to get its promise.\n   - On resolution, we store the result in the corresponding index of the results array and check if all promises have resolved.\n   - If any promise is rejected, we immediately reject the overall promise with the reason.\n\n# Complexity\n- Time complexity: O(n), where n is the number of functions in the array.\nEach function is invoked exactly once, and we wait for all promises to either resolve or reject.\n\n- Space complexity: O(n), due to the storage of the results array, which holds the resolved values for each function.\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\n        let results = new Array(functions.length);\n        let resolvedCount = 0;\n\n        functions.forEach((fn, index) => {\n            fn().then(value => {\n                results[index] = value;\n                resolvedCount++;\n\n                if (resolvedCount === functions.length) {\n                    resolve(results)\n                }\n            }).catch(error => {\n                reject(error)\n            })\n        })\n    })\n};\n```
['JavaScript']