LC 2721
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```javascript []
/**
 * @param {Array<Function>} functions
 * @return {Promise<any>}
 */
var promiseAll = function(functions) {
    var collect = functions.map((fn) => {
        return fn()
    })
    // return Promise.all(collect);
    function returner(collect) {
        let bag = [];
        let counter = 0;
        return new Promise((resolve, reject) => {
            for(let i = 0; i < collect.length; i++) {
                collect[i].then((result) => {
                    bag[i] = result;
                    counter += 1;
                    if(counter === collect.length) {
                        resolve(bag)
                    }
                }).catch((error) => {
                    reject(error);
                })
            }
        })
    }
    return returner(collect);
};

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