Project Euler implementation for JavaScript