Last active
December 19, 2015 23:59
-
-
Save Cycymomo/6037995 to your computer and use it in GitHub Desktop.
140bytes - Récupérer le pgcd d'un nombre variable de nombres (gcd in english) http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
This file contains hidden or 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
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/ | |
function pgcd(){ | |
x=function(a,b){return!b?a:x(b,a%b)};return[].reduce.call(arguments,function(a,b){return x(a,b)}) | |
} |
This file contains hidden or 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
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/ | |
/* by @Barsy at developpez.com */ | |
function pgcd2(){ | |
a=arguments;r=a[i=0];for(;n=a[i++];)while(b=n%r)r=b;return r | |
} |
This file contains hidden or 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
console.log( pgcd(27,36) === 9 ); | |
console.log( pgcd(128,8,32) === 8 ); | |
console.log( pgcd(7,14,7,35,707) === 7 ); | |
console.log( pgcd(13,17) === 1 ); | |
console.log( pgcd(7,7) === 7 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment