function fun(a, b) { a > b || ([a, b] = [b, a]); let k = 1; for (let i = 2; i <= b; ) { if(!(b % i) && !(a % i) ) { b /= i; a /= i; k *= i; } else i++ } return k } alert(fun(20, 30));