Last active
October 21, 2017 12:04
-
-
Save likai24/f78f5d30d4315428e4da3d0040787d12 to your computer and use it in GitHub Desktop.
搜索素数
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
var primes = []; | |
for(var i = 3; i < 10; i++){ | |
var noFactor = true; | |
//console.log('i = ', i); | |
for(var factor = 2; factor < i; factor++){ | |
//console.log('factor = ', factor); | |
// check whether it has factor | |
if(i % factor == 0){ | |
noFactor = false; | |
break; | |
} | |
} | |
if(noFactor) | |
primes.push(i); | |
} | |
//display primes | |
console.log(primes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment