Adding javascript solution for problem 1