Algorithms in JavaScript