Algorithms in Javascript