converted ruby translator to untested javascript