Solving Dromy in JavaScript