Created
October 8, 2014 19:49
-
-
Save shidel-dev/80f6d38f4e691bbd7e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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