Created
February 26, 2018 11:16
-
-
Save felipepastorelima/85689e449be7bf6841c95f1d41f56f89 to your computer and use it in GitHub Desktop.
Extract Method - B
This file contains hidden or 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++) { | |
if (isPrime(i)) { | |
primeNumbers.push(i); | |
} | |
} | |
console.log(primeNumbers); | |
} | |
function isPrime(arg) { | |
if (arg === 0 || arg === 1) { | |
return false; | |
} | |
if (arg === 2) { | |
return true; | |
} | |
for (let i = 2; i <= arg / 2; i++) { | |
if (arg % i === 0) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment