/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function gcm(a, b) { return ( b == 0 )?(a):( gcm(b, a % b) ); }function lcm(a, b) { return ( a / gcm(a,b) ) * b; }function lcm_nums(ar) { if (ar.length > 1) { ar.push( lcm( ar.shift() , ar.shift() ) ); return lcm_nums( ar ); } else { return ar[0]; } }
URL: http://www.ideashower.com/our_solutions/leastgreatest-common-mulitple-lcmgcm-in-php-and-javascript/