Skip to content

Instantly share code, notes, and snippets.

@likai24
Last active October 21, 2017 12:04
Show Gist options
  • Save likai24/f78f5d30d4315428e4da3d0040787d12 to your computer and use it in GitHub Desktop.
Save likai24/f78f5d30d4315428e4da3d0040787d12 to your computer and use it in GitHub Desktop.
搜索素数
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