Skip to content

Instantly share code, notes, and snippets.

@razchiriac
Created March 12, 2017 16:24
Show Gist options
  • Save razchiriac/0bb1f2f4f2647cc743d0d46880146737 to your computer and use it in GitHub Desktop.
Save razchiriac/0bb1f2f4f2647cc743d0d46880146737 to your computer and use it in GitHub Desktop.
GCD // source https://jsbin.com/qupoyi
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>GCD</title>
</head>
<body>
<script id="jsbin-javascript">
// returns the greatest common divisor of a and b
"use strict";
gcd = function (a, b) {
return b === 0 ? a : gcd(b, a % b);
};
console.log(gcd(6, 9));
</script>
<script id="jsbin-source-javascript" type="text/javascript">// returns the greatest common divisor of a and b
gcd = (a,b) => b === 0 ? a : gcd(b,a%b);
console.log(gcd(6,9));</script></body>
</html>
// returns the greatest common divisor of a and b
"use strict";
gcd = function (a, b) {
return b === 0 ? a : gcd(b, a % b);
};
console.log(gcd(6, 9));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment