One-liner solution for Handling Multiple Promise Returns with Promise.all
Intuition\n Describe your first thoughts on how to solve this problem. \n- The problem requires executing multiple asynchronous functions (which return promises
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The problem requires executing multiple asynchronous functions (which return promises) and waiting for all of them to complete before continuing.\n- This scenario is naturally suited for JavaScript\'s ```Promise.all()```, which can wait for multiple promises to resolve and return a promise that resolves with an array of results from the input promises.\n- The challenge lies in calling each function (which returns a promise) and efficiently managing the promises\' resolution.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n#### Function Invocation:\n\n- First, we need to map over the array of functions. For each function, invoke it so that it returns a promise.\n\n#### Promise.all:\n\n- Once we have an array of promises (which we get by calling each function), we can use Promise.all() to wait for all of these promises to resolve or reject.\n- Promise.all() ensures that it returns a single promise that either:\n1. Resolves with an array of results (if all promises resolve successfully), or\n2. Rejects if any of the input promises reject (propagating the first encountered rejection).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTime complexity: O(n + T_max), where n is the number of functions and T_max is the time for the longest promise to resolve.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nSpace complexity: O(n), primarily for storing the array of promises.\n\n# Code\n```javascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function(functions) {\n    return Promise.all(functions.map((fn=>fn()))\n};\n```
['JavaScript']