Execute Asynchronous Functions in Parallel solution ✅🚀
IntuitionThe goal is to mimic the behavior of Promise.all. When dealing with an array of promise-returning functions:
All promises must be resolved before the c
# Intuition
The goal is to mimic the behavior of `Promise.all`. When dealing with an array of promise-returning functions:

- All promises must be resolved before the combined promise resolves.
- If any promise rejects, the combined promise should reject immediately with that error.

The challenge is ensuring the results are resolved in the same order as the input array, even if the promises resolve in a different sequence.
# Approach
- **Empty Array Edge Case**:
    - If the `functions` array is empty, resolve immediately with an empty array.
- **Track Results**:
    - Use an array `res` to store the results, initialized with `null` values matching the length of the input array.
- **Count Resolved Promises**:
    - Maintain a `resolvedCount` variable to track how many promises have resolved.
- **Iterate Over Functions**:
    - Use `forEach` to loop through the `functions` array. For each function:
        - Call the function to execute the promise it returns.
        - Use `await` to wait for the promise resolution.
        - Store the resolved value in the `res` array at the same index.
        - Increment the `resolvedCount`.
- **Check Completion**:
    - If all promises are resolved (`resolvedCount === functions.length`), resolve the outer promise with the `res` array.
- **Handle Errors**:
    - Use a `try-catch` block to handle rejections from individual promises. If any promise rejects, the outer promise immediately rejects with the error.
# Complexity
- Time complexity:
O(n)
Each promise is invoked once, and we iterate through the array once.
- Space complexity:
O(n)
Space is used for the res array to store results and the asynchronous call stack.
# Code
```javascript []
/**
 * @param {Array<Function>} functions
 * @return {Promise<any>}
 */
var promiseAll = async function(functions) {
    return new Promise((resolve,reject) => {
        if(functions.length === 0) {
            resolve([]);
            return;
        }
        
        const res = new Array(functions.length).fill(null);

        let resolvedCount = 0;

        functions.forEach(async (el,idx) => {
            try {
                const subResult = await el();
                res[idx] = subResult;
                resolvedCount++;
                if(resolvedCount=== functions.length) {
                    resolve(res);
                }
            } catch(err) {
                reject(err);
            }
        });
    });
};

/**
 * const promise = promiseAll([() => new Promise(res => res(42))])
 * promise.then(console.log); // [42]
 */
```
['JavaScript']