Last active
March 29, 2019 11:44
-
-
Save ZackFox/4c7c09169ed40378b44ddc8060509eca to your computer and use it in GitHub Desktop.
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 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