Skip to content

Instantly share code, notes, and snippets.

@Saneyan
Created December 12, 2012 12:05
Show Gist options
  • Select an option

  • Save Saneyan/4267274 to your computer and use it in GitHub Desktop.

Select an option

Save Saneyan/4267274 to your computer and use it in GitHub Desktop.
Euclidean algorithm
function gcd ( m, n ){
var remainder;
return m < n ? gcd( n, m ) : ( remainder = m % n ) === 0 ? n : gcd( n, remainder );
}
gcd( 8942555, 144400 ); // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment