Promise all() function internal working explained
IntuitionWe are provided with the array of functions each being a async function with no arguments and returns a promise we need to return a promise which resol
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We are provided with the array of functions each being a async function with no arguments and returns a promise we need to return a promise which resolves if all the  promises of functions array get resolved and return the resolved functions as an array in response and reject the promise if any one of the functions promise fails.

# Approach
<!-- Describe your approach to solving the problem. -->
First, We create a new promise in that we check if functions input array is not empty if yes then we resolve with empty array and return.

**Else** We will count the resolved promises for the functions array. 
We will take a empty data structure which will store the resolved responses of the functions array. 
We will traverse through the functions array and then we resolves each function from functions array and increases counter with each traverse and check if resolved promise counter is equal to functions length. If yes then we resolve the main promise with data structure holding resolved functions response.
Else any error occurs we reject the promise

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
# **O(n)**

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# **O(n)**


# Code
```javascript []
/**
 * @param {Array<Function>} functions
 * @return {Promise<any>}
 */
var promiseAll = function (functions) {
    return new Promise((resolve, reject) => {
        if (functions.length === 0) {
            resolve([])
            return
        }
        // we have created a new array that is has functions length and initaly holds null value
        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']