Javascript implementation of a simple observable Markov chain