Add javascript version of problem 1