Skip to content

Instantly share code, notes, and snippets.

@felipepastorelima
Created February 26, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipepastorelima/7d6dc061735eeb5dacd129ea8b7824f6 to your computer and use it in GitHub Desktop.
Save felipepastorelima/7d6dc061735eeb5dacd129ea8b7824f6 to your computer and use it in GitHub Desktop.
Extract Method - A
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