This is my solution
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[]> {
    if (functions.length === 0) {
        return Promise.resolve([]); // Resolve immediately for an empty array
    }

    const total = functions.length;

    let results: T[] = new Array(total);
    let resolvedCount = 0;

    return new Promise((resolve, reject) => {
        functions.forEach((fn, idx) => {
            fn()
                .then(v => {
                    resolvedCount += 1;
                    results[idx] = v;
                    if (resolvedCount === total) {
                        resolve(results);
                    }
                })
                .catch(reject);
        });
    });
};

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