Easy approach
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((resolve, reject) => {
        const results: T[] = [];
        let completed = 0;

        if (functions.length === 0) {
            resolve(results); // Resolve immediately if no functions are provided
        }

        functions.forEach((fn, index) => {
            fn()
                .then((value) => {
                    results[index] = value; // Store the result at the correct index
                    completed++;

                    if (completed === functions.length) {
                        resolve(results); // Resolve when all promises are done
                    }
                })
                .catch(reject); // Reject immediately if any promise fails
        });
    });
}

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