Created
February 26, 2018 11:18
-
-
Save felipepastorelima/7368736d55f07403ae1fff9391de57d7 to your computer and use it in GitHub Desktop.
Extract Method - C
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 primeNumbersToPrint = primeNumbersBetween(0, 100); | |
console.log(primeNumbersToPrint); | |
} | |
function primeNumbersBetween(min, max) { | |
const result = []; | |
for (let i = min; i <= max; i++) { | |
if (isPrime(i)) { | |
result.push(i); | |
} | |
} | |
return result; | |
} | |
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