js solution, problem 1
improvement to solution