js implementation of markov chains