Added JavaScript solution for problem 2