Skip to content

Instantly share code, notes, and snippets.

@HopefulLlama
Last active August 3, 2016 10:46
Show Gist options
  • Save HopefulLlama/a2e4b2bcd7bbd4da357c825a09123743 to your computer and use it in GitHub Desktop.
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.
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;
}
@HopefulLlama
Copy link
Author

HopefulLlama commented Aug 2, 2016

Sourced from: http://www.blackwasp.co.uk/Coprime.aspx

Published: 06/12/2010

Last accessed: 02/08/2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment