Skip to content

Instantly share code, notes, and snippets.

@bytao7mao
Last active August 7, 2017 04:30
Show Gist options
  • Save bytao7mao/6dcb02849107e3c271c33b2e2b9b0c16 to your computer and use it in GitHub Desktop.
Save bytao7mao/6dcb02849107e3c271c33b2e2b9b0c16 to your computer and use it in GitHub Desktop.
JS how to find the greatest common divisor
function div(a, b) {
if (!b) //!b can be replaced with b===0
{ return a; }
return div(b, a % b);
};
@bytao7mao
Copy link
Author

bytao7mao commented Aug 5, 2017

in ternary
function div(a,b) {
return (!b) ? a: div(b,a%b);
};

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