Skip to content

Instantly share code, notes, and snippets.

@KimSarabia
Created October 13, 2017 21:05
Show Gist options
  • Save KimSarabia/7834ae0ec4b6509032b10aca1036da55 to your computer and use it in GitHub Desktop.
Save KimSarabia/7834ae0ec4b6509032b10aca1036da55 to your computer and use it in GitHub Desktop.
Greatest Common Denominator in JavaScript
function gcd(a,b){if(b===0) return a; return gcd(b,a%b)}
// ES6
let gcd = (a,b) => (b===0) ? a : gcd(b,a%b)
// Original: Java
// public int GCD(int a, int b) {
// if (b==0) return a;
// return GCD(b,a%b);
// }
// public int GCD(int a, int b) { return b==0 ? a : GCD(b, a%b); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment