Implementing Dominion in javascript