Clean Solution in O(n) Time
Intuitioninput = arrayoutput = arraydesc = execute async functions in parallel and return an array of values. if any of them throw an error, reject with the fir
# Intuition
input = array
output = array
desc = execute async functions in parallel and return an array of values. if any of them throw an error, reject with the first error message
implementation = push results to an array by index as they return

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```javascript []
/**
 * @param {Array<Function>} functions
 * @return {Promise<any>}
 */
const promiseAll = (functions) => {
  return new Promise((resolve, reject) => {
    const result = Array.from({ length: functions.length }).fill(null);
    let resolved = 0;
    for (let idx = 0; idx < functions.length; idx++) {
      const fn = functions[idx];
      fn()
        .then((res) => {
          result[idx] = res;
          resolved++;
          if (resolved == functions.length) {
            resolve(result);
          }
        })
        .catch((err) => {
          reject(err);
        });
    }
  });
};
```
['JavaScript']