solution to project euler problem 7; javascript