Skip to content

Instantly share code, notes, and snippets.

@VoloshchenkoAl
Created March 10, 2017 15:42
Show Gist options
  • Save VoloshchenkoAl/b35d9bdda6628412cee48bcfc4de604c to your computer and use it in GitHub Desktop.
Save VoloshchenkoAl/b35d9bdda6628412cee48bcfc4de604c to your computer and use it in GitHub Desktop.
function isPrime(value) {
if (!isPrime.answers) {
isPrime.answers = {};
}
if (isPrime.answers[value] !== null) {
return isPrime.answers[value];
}
var prime = value != 1;
for (var i = 2; i < value; i++) {
if (value % i == 0) {
prime = false;
break;
}
}
return isPrime.answers[value] = prime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment