function gcd(p,q){ if(q == 0){ return p; }else{ var r = p % q; return gcd(q, r); } }; gdc(12,8); //4