Solution
Code


# Code
```javascript []
/**
 * @param {Array<Function>} functions
 * @return {Promise<any>}
 */
var promiseAll = function (functions) {
    return new Promise((resolve, reject) => {
        if (functions.length === 0) {
            resolve([]);
            return;
        }

        let results = new Array(functions.length);
        let completed = 0;
        let hasRejected = false;

        functions.forEach((fn, index) => {
            fn()
                .then(value => {
                    if (hasRejected) return;
                    results[index] = value;
                    completed++;
                    if (completed === functions.length) {
                        resolve(results);
                    }
                })
                .catch(error => {
                    if (!hasRejected) {
                        hasRejected = true;
                        reject(error);
                    }
                });
        });
    });
};

/**
 * Example Usage:
 */
const functions1 = [
    () => new Promise(resolve => setTimeout(() => resolve(5), 200))
];

const functions2 = [
    () => new Promise(resolve => setTimeout(() => resolve(1), 200)),
    () => new Promise((_, reject) => setTimeout(() => reject("Error"), 100))
];

const functions3 = [
    () => new Promise(resolve => setTimeout(() => resolve(4), 50)),
    () => new Promise(resolve => setTimeout(() => resolve(10), 150)),
    () => new Promise(resolve => setTimeout(() => resolve(16), 100))
];

promiseAll(functions1).then(console.log).catch(console.error); 
promiseAll(functions2).then(console.log).catch(console.error); 
promiseAll(functions3).then(console.log).catch(console.error); 

```
['JavaScript']