Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Last active December 19, 2015 23:59
Show Gist options
  • Save Cycymomo/6037995 to your computer and use it in GitHub Desktop.
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/
// 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)})
}
// 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
}
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