"content":"<p>Given an array of asynchronous functions <code>functions</code>, return a new promise <code>promise</code>. Each function in the array accepts no arguments and returns a promise. All the promises should be executed in parallel.</p>\n\n<p><code>promise</code> resolves:</p>\n\n<ul>\n\t<li>When all the promises returned from <code>functions</code> were resolved successfully in parallel. The resolved value of <code>promise</code> should be an array of all the resolved values of promises in the same order as they were in the <code>functions</code>. The <code>promise</code> should resolve when all the asynchronous functions in the array have completed execution in parallel.</li>\n</ul>\n\n<p><code>promise</code> rejects:</p>\n\n<ul>\n\t<li>When any of the promises returned from <code>functions</code> were rejected. <code>promise</code> should also reject with the reason of the first rejection.</li>\n</ul>\n\n<p>Please solve it without using the built-in <code>Promise.all</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> functions = [\n () => new Promise(resolve => setTimeout(() => resolve(5), 200))\n]\n<strong>Output:</strong> {"t": 200, "resolved": [5]}\n<strong>Explanation:</strong> \npromiseAll(functions).then(console.log); // [5]\n\nThe single function was resolved at 200ms with a value of 5.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> functions = [\n () => new Promise(resolve => setTimeout(() => resolve(1), 200)), \n () => new Promise((resolve, reject) => setTimeout(() => reject("Error"), 100))\n]\n<strong>Output:</strong> {"t": 100, "rejected": "Error"}\n<strong>Explanation:</strong> Since one of the promises rejected, the returned promise also rejected with the same error at the same time.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> functions = [\n () => new Promise(resolve => setTimeout(() => resolve(4), 50)), \n () => new Promise(resolve => setTimeout(() => resolve(10), 150)), \n () => new Promise(resolve => setTimeout(() => resolve(16), 100))\n]\n<strong>Output:</strong> {"t": 150, "resolved": [4, 10, 16]}\n<strong>Explanation:</strong> All the promises resolved with a value. The returned promise resolved when the last promise resolved.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>functions</code> is an array of functions that returns promises</li>\n\t<li><code>1 <= functions.length <= 10</code></li>\n</ul>\n",
"envInfo":"{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 5.1.6, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2022 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",