Created
February 26, 2018 11:11
-
-
Save felipepastorelima/7d6dc061735eeb5dacd129ea8b7824f6 to your computer and use it in GitHub Desktop.
Extract Method - A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printPrimeNumbersFromZeroToHundred() { | |
const primeNumbers = []; | |
for (let i = 0; i <= 100; i++) { | |
let isPrime = true; | |
if (i < 2) { | |
isPrime = false; | |
} else if(i === 2) { | |
isPrime = true; | |
} else { | |
isPrime = true; | |
for (let j = 2; j <= i / 2; j++) { | |
if (i % j === 0) { | |
isPrime = false; | |
} | |
} | |
} | |
if (isPrime) { | |
primeNumbers.push(i); | |
} | |
} | |
console.log(primeNumbers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment