Skip to content

Instantly share code, notes, and snippets.

@shidel-dev
Created October 8, 2014 19:49
Show Gist options
  • Save shidel-dev/80f6d38f4e691bbd7e91 to your computer and use it in GitHub Desktop.
Save shidel-dev/80f6d38f4e691bbd7e91 to your computer and use it in GitHub Desktop.
Number.prototype.isCoprimeTo = function(num) {
if (this>num) var small = num, big = this;
else var small = this, big = num;
return (function(a, b) {
if (b == 0) return a;
return arguments.callee(b, a % b);
})(small, big) == 1
}
//======example two=======
function isCoprimeTo(num1, num2){
if (num1>num2) var small = num2, big = num1;
else var small = num1, big = num2;
return (function gcd(a,b){
if (b == 0) return a;
return gcd(b, a % b);
})(small,big) == 1
}
//===tests==
var myNum = 35;
console.log(myNum.isCoprimeTo(64) == true)
console.log(isCoprimeTo(64,35) == true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment