solved translate from Ruby Javascript problem