DEV Community

Discussion on: Project Euler #1 - Multiples of 3 and 5

Collapse
 
matheus profile image
Matheus Calegaro • Edited

Here it is ¯\_(ツ)_/¯
I'm looking forward for feedbacks

let sum = 0,                                        
    i = 0

  for (i = 0; i < 1000; i++) {
    if (i % 3 === 0 || i % 5 === 0) sum += i
  }

console.log('The sum is %d', sum)
Collapse
 
gmartigny profile image
Guillaume Martigny

Smallest nitpicking ever: declare i inside the for loop.

for (let i = 0; i < 1000; i++)

It will prevent it from leaking outside the loop.

Collapse
 
jacobmgevans profile image
Jacob Evans

I wouldn't even call that nitpicking, that is solid best practice advice to avoid memory leaks.