Skip to content

Instantly share code, notes, and snippets.

@plugn
Last active February 11, 2020 23:49
Show Gist options
  • Save plugn/fd2218f0067e0cf22ced79589925cd3b to your computer and use it in GitHub Desktop.
Save plugn/fd2218f0067e0cf22ced79589925cd3b to your computer and use it in GitHub Desktop.
greater common divisor
function gcd (a, b) {
if (a === b) {
return a
}
const major = a > b ? a : b
const minor = a > b ? b : a
for (let i = minor; i > 0; --i) {
if (major % i === 0 && minor % i === 0) {
break;
}
}
return i
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment