Fully-generic markov-chain module in javascript