Skip to content

Instantly share code, notes, and snippets.

@kauffmanes
Created September 5, 2017 13:16
Show Gist options
  • Save kauffmanes/ed67bf176af7fd0a5a1c2201b9239448 to your computer and use it in GitHub Desktop.
Save kauffmanes/ed67bf176af7fd0a5a1c2201b9239448 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/geyaba
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/*
* Reference:
* https://www.quora.com/Is-every-prime-number-other-than-2-
* and-3-of-the-form-6k%C2%B11-Is-this-a-proven-result-What-
* are-other-resources-about-it
*/
function isPrime (n) {
if (!n) { return "No value provided."; }
if (!Number.isInteger(n)) { return "'" + n + "' is not an integer."; }
if (n <= 1) { return false; }
/* Special cases: 2 and 3 don't match 6k-1 and 6k+1 check */
if (n == 2) { return true; }
if (n == 3) { return true; }
if (n % 2 === 0) { return false; }
if (n % 3 === 0) { return false; }
var i = 5;
var w = 2;
//handles #s > 25, not divisible by 2, 3
while (i*i <= n) {
if (n % i === 0) { return false; }
i += w;
w = 6 - w;
}
return true;
}
// for (var i=10;i<100;i++) {
// console.log(i + ': ' + isPrime(i));
// }
console.log(isPrime());
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
* Reference:
* https://www.quora.com/Is-every-prime-number-other-than-2-
* and-3-of-the-form-6k%C2%B11-Is-this-a-proven-result-What-
* are-other-resources-about-it
*/
function isPrime (n) {
if (!n) { return "No value provided."; }
if (!Number.isInteger(n)) { return "'" + n + "' is not an integer."; }
if (n <= 1) { return false; }
/* Special cases: 2 and 3 don't match 6k-1 and 6k+1 check */
if (n == 2) { return true; }
if (n == 3) { return true; }
if (n % 2 === 0) { return false; }
if (n % 3 === 0) { return false; }
var i = 5;
var w = 2;
//handles #s > 25, not divisible by 2, 3
while (i*i <= n) {
if (n % i === 0) { return false; }
i += w;
w = 6 - w;
}
return true;
}
// for (var i=10;i<100;i++) {
// console.log(i + ': ' + isPrime(i));
// }
console.log(isPrime());</script></body>
</html>
/*
* Reference:
* https://www.quora.com/Is-every-prime-number-other-than-2-
* and-3-of-the-form-6k%C2%B11-Is-this-a-proven-result-What-
* are-other-resources-about-it
*/
function isPrime (n) {
if (!n) { return "No value provided."; }
if (!Number.isInteger(n)) { return "'" + n + "' is not an integer."; }
if (n <= 1) { return false; }
/* Special cases: 2 and 3 don't match 6k-1 and 6k+1 check */
if (n == 2) { return true; }
if (n == 3) { return true; }
if (n % 2 === 0) { return false; }
if (n % 3 === 0) { return false; }
var i = 5;
var w = 2;
//handles #s > 25, not divisible by 2, 3
while (i*i <= n) {
if (n % i === 0) { return false; }
i += w;
w = 6 - w;
}
return true;
}
// for (var i=10;i<100;i++) {
// console.log(i + ': ' + isPrime(i));
// }
console.log(isPrime());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment