cheese
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
```typescript []
type Fn<T> = () => Promise<T>

function promiseAll<T>(functions: Fn<T>[]): Promise<T[]> {
    return new Promise((res, rej) => {
        let finishedCount = 0;
        const response = Array(functions.length);

        for (const [i, fn] of Object.entries(functions)) {
            fn().then(v => {
                response[i] = v;
                finishedCount++;
                if (finishedCount === functions.length) {
                    res(response);
                }
            }).catch(e => rej(e))
        }
    })
};

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