Moved to JavaScript.
Added tests.