Created
March 10, 2017 15:42
-
-
Save VoloshchenkoAl/b35d9bdda6628412cee48bcfc4de604c 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
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