solution to project euler problem 6; javascript