Euler problem 2 in js