Last active
August 3, 2016 10:46
-
-
Save HopefulLlama/a2e4b2bcd7bbd4da357c825a09123743 to your computer and use it in GitHub Desktop.
JavaScript implementation of Euclid's Algorithm (Modulus based); Tests whether two numbers are co-prime or not.
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 getGreatestCommonDivisor(x, y) { | |
while(x !== 0 && y !== 0) { | |
if(x > y) { | |
x %= y; | |
} else { | |
y %= x; | |
} | |
} | |
return Math.max(x, y); | |
} | |
function isCoprime(x, y) { | |
return getGreatestCommonDivisor === 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sourced from: http://www.blackwasp.co.uk/Coprime.aspx
Published: 06/12/2010
Last accessed: 02/08/2016