Skip to content

Instantly share code, notes, and snippets.

View Dhana-Krishnasamy's full-sized avatar
🎯
Focusing

Dhana Dhana-Krishnasamy

🎯
Focusing
View GitHub Profile
@Dhana-Krishnasamy
Dhana-Krishnasamy / Trie.js
Created November 11, 2019 22:14 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;
@Dhana-Krishnasamy
Dhana-Krishnasamy / parallelly.js
Created October 3, 2018 12:52
Control the parallel execution of async tasks. Useful if you want to limit how many parallel async operations are inflight at a time.
/**
* Control the parallel execution of async tasks.
* This function is useful where you want to send out many http requests, but want to control how many inflight requests are inplay at a time.
*
* @name parallelly
* @function
* @param {Function} target - This function will be invoked with a taskId (zero based). taskId can be used to ,say, access an item in the queue.
* @param {number} concurrencyLevel - How many parallel invocations of target should happen at any given time
* @param {number} queueLength - How many times the target should be invoked in total
* @return {Promise} Resolves when target is invoked queueLength times or one of the invocations of the target throw an error.