Skip to content

Instantly share code, notes, and snippets.

@kbiedrzycki
Last active July 15, 2016 08:45
Show Gist options
  • Save kbiedrzycki/59a926ed1e82273ee7e4c879839530dd to your computer and use it in GitHub Desktop.
Save kbiedrzycki/59a926ed1e82273ee7e4c879839530dd to your computer and use it in GitHub Desktop.
Function for checking if number is prime (matching regular expression of unary value)
module.exports = function(value) {
const primeVerifyExpression = /^1?$|^(11+?)\1+$/;
const unaryValue = '1'.repeat(value);
return !primeVerifyExpression.test(unaryValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment