Over a million developers have joined DZone.

Greatest Common Divisor //JavaScript Function

·


[UPDATED CODE AND HELP CAN BE FOUND HERE]


usage


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


code


//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/math/mdc [v1.0]

mdc = function(o){
	if(!o.length)
		return 0;
	for(var r, a, i = o.length - 1, b = o[i]; i;)
		for(a = o[--i]; r = a % b; a = b, b = r);
	return b;
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}