solution to project euler 2; javascript