Skip to content

Instantly share code, notes, and snippets.

@ZackFox
Last active March 29, 2019 11:44
Show Gist options
  • Save ZackFox/4c7c09169ed40378b44ddc8060509eca to your computer and use it in GitHub Desktop.
Save ZackFox/4c7c09169ed40378b44ddc8060509eca to your computer and use it in GitHub Desktop.
function GCD(a,b){
let res;
for(let i = 0; i< Math.max(a,b); i++){
if(a % i === 0 && b % i === 0){
res = i;
}
}
return res
}
function GCD(a,b){
while(true){
if(a === 0) return b;
if(b === 0) return a;
if(a >= b){
a = a % b;
}
else{
b = b % a;
}
}
}
function GCD(a,b){
if(a === 0) return b;
if(b === 0) return a;
while(a !== b){
if(a > b){
a = a - b;
}
else{
a = b - a;
b = a;
}
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment