These are by no means the perfect implementations, however I tried to heavily annotate them so you could easily adapt them to the demands of a given problem.
Feel free to drop me a line at email@example.com with any feedback or requests! Don't forget to star if you find this useful!
Some notes on the JS conventions I use:
- In for loops, I always create an n variable to store lengths of arrays and strings (i.e. for (var i = 0, n = arr.length; i < n;...)). Some JS compilers continuously recalculate the length if you do something like i < arr.length, so this syntax is safer for computational efficiency.