Solving project euler problems in Javascript