leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit e0289b589d9be7030c3087e60182754341629590
parent 4516e1c87425148e4e5bb8c168a02971491ed9bd
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 17 May 2023 22:17:32 +0200

JavaScript Challenge: Day 13

Diffstat:
AProblems/2636.js | 16++++++++++++++++
MREADME.md | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Problems/2636.js b/Problems/2636.js @@ -0,0 +1,16 @@ +/** + * @param {Function[]} functions + * @param {number} n + * @return {Function} + */ + +var promisePool = async function(functions, n) { + async function evaluateNext() { + if (functions.length === 0) return; + const fn = functions.shift(); + await fn(); + await evaluateNext(); + } + const nPromises = Array(n).fill().map(evaluateNext); + await Promise.all(nPromises); +}; diff --git a/README.md b/README.md @@ -548,6 +548,7 @@ for solving problems. | 2632 | Medium | [Curry](Problems/2632.js) | | 2634 | Easy | [Filter Elements from Array](Problems/2634.js) | | 2635 | Easy | [Apply Transform Over Each Element in Array](Problems/2635.js) | +| 2636 | Medium | [Promise Pool ](Problems/2636.js) | | 2637 | Easy | [Promise Time Limit](Problems/2637.js) | | 2665 | Easy | [Counter II](Problems/2665.js) | | 2666 | Easy | [Allow One Function Call](Problems/2666.js) |