Javascript version

Not as succinct as python or ruby, but may be useful for making a web version