Platinum Partner

Minimum Common Multiple //Javascript Function


Minimum Common Multiple

[UPDATED CODE AND HELP CAN BE FOUND HERE]



Code


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

MCM = function( divisors ){
	for( var i, j, n, d, r = 1, x = divisors; ( n = x.pop() ) != undefined; )
		while( n > 1 ){
			if( !( n % 2 ) )
				d = 2;
			else {
				for ( i = 3, j = Math.floor( Math.sqrt( n ) ); i <= j && n % i; i += 2 );
				d = i <= j ? i : n;
			}
			for( i in ( n /= d, r *= d, x ) )
				x.splice( i, !( x[i] % d ) && ( x[i] /= d ) == 1 );
		}
	return r;
}



Usage


alert( MCM( [2, 2, 4, 6, 9] ) );
{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}