[JavaScript] promise
\n\nvar promiseAll = function(functions) {\n    return new Promise((resolve, reject) => {\n        let n = functions.length;\n        const ans = Array(n); \n  
\n```\nvar promiseAll = function(functions) {\n    return new Promise((resolve, reject) => {\n        let n = functions.length;\n        const ans = Array(n); \n        functions.forEach((fn, i) => {\n            fn()\n            .then(val => {\n                ans[i] = val; \n                if (--n === 0) resolve(ans); \n            })\n            .catch(error => reject(error));\n        });\n    });\n};\n```
['JavaScript']