Solution to Project Euler problems in JavaScript