1 LoC
Intuition\n Describe your first thoughts on how to solve this problem. \nMy initial thought was that there was an array of promises being passed in, and I neede
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy initial thought was that there was an array of promises being passed in, and I needed a new promise to run each of these in parallel. \nThis turned out to be wrong, there is an array of functions that return promises, not an array of promises.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTried to run all the functions in parallel before realising that they returned promises (rather than were promises).\n\nOnce I realised that I put each function call result into an array and returned promise.all as the docs say that returns values in the same order as promises given, so it does the complexity of mapping results back to the correct index on it\'s own.\n\nThen refactored to use map() instead of a foreach.\nThen refactored into just 1 line of code.\n\n# Code\n```javascript []\n/**\n * @param {Array<Function>} functions\n * @return {Promise<any>}\n */\nvar promiseAll = function (functions) {\n    return Promise.all(functions.map(f => f()));\n};\n\n/**\n * const promise = promiseAll([() => new Promise(res => res(42))])\n * promise.then(console.log); // [42]\n */\n```
['JavaScript']