Finally
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function (functions) {\n  let k = new Promise((resolve,reject) => {\n    let arar = [];\n\n    functions.forEach((p,i) => {\n      p().then((d) => {\n        arar.push({d,i});\n\n        if (arar.length === functions.length)\n          {\n            arar.sort((a,b)=>a.i-b.i)              \n\n            for(let k in arar)\n            {\n\n              arar[k]=arar[k].d\n            }\n            \n\n            resolve(arar);\n          } \n      }).catch(e=>reject(e));\n\n     \n\n\n    });\n  });\n\n   \n\n  return k.catch(e=>{throw e});\n};\n\n\n/**\n * const promise = promiseAll([() => new Promise(res => res(42))])\n * promise.then(console.log); // [42]\n */\n```
['JavaScript']