see the notes if you are struggling with promises.
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 
# 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    //return a promise\n    return new Promise((resolve, reject) => {\n        //create arrary to store the results in correct order\n        //the counter will tracked the settled promises \n    let results = [], settled = 0;\n    //forEach () method exexutes the func for each elmement in the array.\n    //[i] is used to store the results in correct order\n    functions.forEach((func,i)=> \n    //handle the promise resolution:  func().then(res => {})\n    func().then(res => {\n        //each func is resolved the value is stored in correct order in the results array\n        results[i] = res;\n        //once the promise resolves the counter increments \n        if (++settled === functions.length)resolve(results);\n    }).catch(reject) //handle rejection \n    );\n    });\n};\n\n\n// const promise = promiseAll([() => new Promise(res => res(42))])\n// promise.then(console.log); // [42]\n\n```
['JavaScript']