2721. Execute Asynchronous Functions in Parallel
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 []
var promiseAll = function(functions) {
    return new Promise((resolve, reject) => {
        let results = [];
        let count = 0;
        let errorOccurred = false;

        for (let i = 0; i < functions.length; i++) {
            functions[i]().then(result => {
                if (errorOccurred) return; // if an error occurred, do nothing
                results[i] = result;
                count++;
                if (count === functions.length) {
                    resolve(results);
                }
            }).catch(error => {
                if (!errorOccurred) {
                    errorOccurred = true;
                    reject(error);
                }
            });
        }
    });
};

```
['JavaScript']