Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Greatest Common Divisor //JavaScript Function



[UPDATED CODE AND HELP CAN BE FOUND HERE]


usage

   1  
   2  alert(mdc([8, 4, 12]));


code

   1  
   2  //+ Jonas Raoni Soares Silva
   3  //@ http://jsfromhell.com/math/mdc [v1.0]
   4  
   5  mdc = function(o){
   6  	if(!o.length)
   7  		return 0;
   8  	for(var r, a, i = o.length - 1, b = o[i]; i;)
   9  		for(a = o[--i]; r = a % b; a = b, b = r);
  10  	return b;
  11  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS