Implementation of some algorithms in JavaScript