Created
September 15, 2016 02:54
-
-
Save kidGodzilla/509e807efdedba14a9fd8f5511d03a2a to your computer and use it in GitHub Desktop.
Simple Primes
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
// ES5 :) | |
function isPrime (n) { | |
for (i = 2; i < n; i++) | |
if (n % i === 0) return false | |
return true | |
} | |
// ES6 (readable) | |
isPrime = n => { for (i = 2; i < n; i++) if (n % i === 0) return false; return true } | |
// ES6 (Codegolfed to 55chars) | |
isPrime=n=>{for(i=2;i<n;i++)if(n%i==0)return false;return true} | |
// AssertGolf | |
assert=(c,t)=>{c?console.log(t):console.warn(t)} | |
// Tests | |
assert(isPrime(0)==1, "Zero is prime") | |
assert(isPrime(2)==1, "Two is prime") | |
assert(isPrime(3)==1, "Three is prime") | |
assert(isPrime(4)==0, "Four is not prime") | |
assert(isPrime(5)==1, "Five is prime") | |
assert(isPrime(6)==0, "Six is not prime") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment