Euclidean algorithm as a one-line function:
function gcd(a,b){ return b ? gcd(b, a%b) : a; } function gcd(a,b){ return b ? gcd(b, a%b) : a; }If A is less than B it calls itself with the terms reversed.